Solved

Onclick not working in firefox but does in IE

Posted on 2006-06-19
19
4,049 Views
Last Modified: 2008-01-09
Hello, I have a simple onclick that works in IE but not in firefox. I was wondering if its written wrong or what the problem is.

 <tr>
          <td width="63"><a href="#" onClick="javascript:doPassVar('1.xml')">Link 1</a></td>
        </tr>
        <tr>
          <td><a href="#" onClick="javascript:doPassVar('2.xml')">Link 2</a> </td>
        </tr>
        <tr>
          <td><a href="#" onClick="javascript:doPassVar('3.xml')" onMouseDown="javascript:doPassVar('3.xml')">Link 3</a></td>
        </tr>


Thanks
0
Comment
Question by:cwitr329
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 4
  • +2
19 Comments
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16940255
I have never really researched this, however, I think the "javascript:" syntax is used only when you use it in the HREF part, i.e. a href="javascript:".
Remove "javascript:" from your onclick events and everything should work just fine.
0
 
LVL 30

Expert Comment

by:third
ID: 16940308
put a return false after calling your function. this will prevent the href from executing.

<tr>
          <td width="63"><a href="#" onClick="doPassVar('1.xml');return false;">Link 1</a></td>
        </tr>
        <tr>
          <td><a href="#" onClick="doPassVar('2.xml');return false;">Link 2</a> </td>
        </tr>
        <tr>
          <td><a href="#" onClick="doPassVar('3.xml');return false;">Link 3</a></td>
        </tr>
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16940340
as far as I know, only HREF javascript needs false return or void... if you put it into an event, you don't need that, as you are not redirecting anything
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 

Author Comment

by:cwitr329
ID: 16940344
Thank guys, gave both of the suggestions above a try and still nothing... I click on it and its not executed. Anymore ideas?
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16940390
Then the only explanation I can produce is that your script (doPassVar) is not cross-browser and therefore does not work under other browsers than MSIE.
Try executing that in Opera what will it do.
Also, you can take a look at the JavaScript Console in Firefox (under Tools menu item) and check what errors your JavaScript produces when executed in Firefox.
0
 

Author Comment

by:cwitr329
ID: 16940449
CyberGhost, thanks for the responses. I checked out the error javascript is producing and it says line 12 which is:

window.document.flashMovie.SetVariable("xmlVar", sendText);

Do you see a problem with that line? Thanks
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16940494
Cyberghost:
ALWAYS return false on an onClick event of a link. You may not see it, but the link IS followed
Try it on a page with animated gifs and you will see they stop if you do not return false.

@cwitr: please show the code.
My guess is you are accessing an activeX object in firefox without having the activeX plugin installed.
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16940553
mplungjan:
you are right about the link, I ment this a bit more globally - you don't need to return false when clicking on a button :-)
However, it is really right to return false onClick, so if a person is at the bottom of page, s/he won't be put on top of that page where the # anchor resides :-)

cwitr329:
you might want to try the Flash/JavaScript integration kit (http://www.permadi.com/tutorial/flashjscommand/)
OR
you can still take a look here: http://www.permadi.com/tutorial/flashjscommand/
... it worked under my FF, too :-)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16940701
Also the javascript: IS needed in event handlers in IE if the first script on the page is NOT JavaScript (VBScript for example) otherwise you will get VBScript errors when using javascript syntax
0
 

Author Comment

by:cwitr329
ID: 16940735
Thanks again for the comments. Heres more complete code, but I still do not know whats wrong...

<script language="JavaScript" type="text/javascript">
<!--
function doPassVar(args){
      var sendText = args;
      window.document.flashMovie.SetVariable("xmlVar", sendText);
            


      
}
//-->
</SCRIPT>
<script language="JavaScript" type="text/javascript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>
0
 
LVL 6

Expert Comment

by:CyberGhost
ID: 16940762
mplungjan:
well, learning every day ... I did not take VBScripting into consideration as I try to do cross-browser cross-platform scripts each time :-)

cwitr329:
what exact error does the JavaScript produce in Firefox?
0
 
LVL 30

Expert Comment

by:third
ID: 16940802
try,

function doPassVar(args){
     var sendText = args;
     var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
     var movie = InternetExplorer ? window.flashMovie : window.document.flashMovie;
     movie.SetVariable("xmlVar", sendText);    
}

0
 
LVL 30

Expert Comment

by:third
ID: 16940820
or use the getFlashMovieObject function on the link provided by CyberGhost.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 16941260
@cwitr329 - Not enough code. We also need to see how you embed your flash in the html and how you execute the script you have problem with
0
 
LVL 25

Expert Comment

by:devic
ID: 16941658
<a href="http://www.google.com/search?q=" onclick="this.href+='always coca cola';">never say never ;)</a>
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 250 total points
ID: 16942174
Rewrite (read what I mean, not what I wrote) :

ALWAYS return false on an onClick event of a link that does not modify the href. You may not see it, but the link IS followed
Try it on a page with animated gifs and you will see they stop if you do not return false.
Also page will reload if href="#" and there is no return false
0
 

Author Comment

by:cwitr329
ID: 16944164
OK I will paste the code below. Before you comment how messy it is, its just for testing purposed :)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<script language="JavaScript" type="text/javascript">
<!--
function doPassVar(args){
      var sendText = args;
      window.document.flashMovie.SetVariable("xmlVar", sendText);
            


      
}
//-->
</SCRIPT>
<script language="JavaScript" type="text/javascript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//-->
</script>

<style>
#myFlash{
      position:absolute;
      left:30px;
      top:53px;
      height: 536px;
      width: 770px;
}
</style>
<link href="House%20of%20Notes_files/styles.css" rel="stylesheet" type="text/css">
</head>

<body>

<script type="text/javascript" src="embed.js"></script>

<TABLE class=SampleTable id=Table1 cellSpacing=0 cellPadding=0 width=790
border=0>
  <TBODY>
    <TR>
      <TD>
        <TABLE id=Table1 cellSpacing=0 cellPadding=0 width=790 border=0>
          <TBODY>
            <TR>
              <TD><LINK href="House of Notes_files/styles.css" type=text/css
            rel=stylesheet>
                  <TABLE id=Table1 height=90 cellSpacing=1 cellPadding=1 width=780
            border=0>
                    <TBODY>
                      <TR>
                        <TD vAlign=center width=350><IMG
                  src="House of Notes_files/logo.gif"></TD>
                        <TD align=right width=430>
                          <TABLE id=Table2 height=90 cellSpacing=0 cellPadding=0
                  width=400 border=0>
                            <TBODY>
                              <TR>
                                <TD align=right height=60>
                                  <TABLE id=Table3 cellSpacing=1 cellPadding=1 width=270
                        border=0>
                                    <TBODY>
                                      <TR>
                                        <TD align=middle width=90><IMG
                              src="House of Notes_files/icoHome.gif"></TD>
                                        <TD align=middle width=90><IMG
                              src="House of Notes_files/icoContact.gif"></TD>
                                        <TD align=middle width=90><IMG
                              src="House of Notes_files/icoCart.gif"></TD>
                                      </TR>
                                      <TR>
                                        <TD align=middle width=90><A class=TopLink
                              id=Header1_Top1_hlHome
                              href="http://www.houseofnotes.com/Browser/Index.aspx">Home</A></TD>
                                        <TD align=middle width=90><A class=TopLink
                              id=Header1_Top1_hlContact
                              href="http://www.houseofnotes.com/Browser/Contact.aspx">Contact</A></TD>
                                        <TD align=middle width=90><A class=TopLink
                              id=Header1_Top1_hlCart
                              href="http://www.houseofnotes.com/Browser/ViewCart.aspx">View Cart</A></TD>
                                      </TR>
                                    </TBODY>
                                </TABLE></TD>
                              </TR>
                              <TR>
                                <TD align=right height=30>
                                  <TABLE id=Table4 cellSpacing=1 cellPadding=1 width=400
                        border=0>
                                    <TBODY>
                                      <TR>
                                        <TD width=170><INPUT class=topTextBox
                              id=Header1:Top1:txtSearch style="WIDTH: 160px"
                              value=Search name=Header1:Top1:txtSearch></TD>
                                        <TD width=125><SELECT class=topDropDown
                              id=Header1_Top1_ddlSearch style="WIDTH: 108px"
                              name=Header1:Top1:ddlSearch>
                                            <OPTION value=1
                                selected>Entire Site</OPTION>
                                        </SELECT></TD>
                                        <TD align=middle width=80><INPUT class=siteButton id=Header1_Top1_btnSearch style="WIDTH: 75px" type=submit value=Search name=Header1:Top1:btnSearch></TD>
                                      </TR>
                                    </TBODY>
                                </TABLE></TD>
                              </TR>
                            </TBODY>
                        </TABLE></TD>
                      </TR>
                    </TBODY>
                </TABLE></TD>
            </TR>
            <TR>
              <TD><LINK href="House of Notes_files/styles.css" type=text/css
            rel=stylesheet>
                  <TABLE id=Table1 cellSpacing=0 cellPadding=0 width=790 border=0>
                    <TBODY>
                      <TR>
                        <TD class=menuBack vAlign=center align=middle>
                          <TABLE id=Table2 cellSpacing=1 cellPadding=1 width=780
                  border=0>
                            <TBODY>
                              <TR>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlHome
                        href="http://www.houseofnotes.com/Browser/Index.aspx">Home</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlLogin
                        href="http://www.houseofnotes.com/Browser/Login.aspx">Login</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlRegister
                        href="http://www.houseofnotes.com/Browser/Register.aspx">Register</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlHow
                        href="http://www.houseofnotes.com/Browser/How.aspx">How it works</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlFAQ
                        href="http://www.houseofnotes.com/Browser/FAQ.aspx">FAQ</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlHelp
                        href="http://www.houseofnotes.com/Browser/Help.aspx">Help</A></TD>
                                <TD align=middle width=111><A class=menuLink
                        id=Header1_Menu1_hlTutorials
                        href="http://www.houseofnotes.com/Browser/Tutorials.aspx">Tutorials</A></TD>
                              </TR>
                            </TBODY>
                        </TABLE></TD>
                      </TR>
                    </TBODY>
                </TABLE></TD>
            </TR>
          </TBODY>
      </TABLE></TD>
    </TR>
    <TR>
      <TD align=middle><BR>
      </TD>
    </TR>
    <TR>
      <TD><LINK href="House of Notes_files/styles.css" type=text/css
      rel=stylesheet>
          <TABLE id=Table1 cellSpacing=1 cellPadding=1 width="100%" border=0>
            <TBODY>
              <TR>
                <TD class=footerback vAlign=center align=middle></TD>
              </TR>
              <TR>
                <TD class=footerLink vAlign=center align=middle height=30><A
            class=footerLink id=Footer1_hlPrivacy
            href="http://www.houseofnotes.com/Browser/Privacy.aspx">Privacy</A>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; <A class=footerLink id=Footer1_hlTerms
            href="http://www.houseofnotes.com/Browser/Terms.aspx">Terms of Use</A>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; <A class=footerLink
            id=Footer1_hlJobs
            href="http://www.houseofnotes.com/Browser/Jobs.aspx">Jobs</A>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; <A class=footerLink id=Footer1_hlMyPanel
            href="http://www.houseofnotes.com/Browser/MyPanel.aspx">My Panel</A>&nbsp;&nbsp;&nbsp; |&nbsp;&nbsp;&nbsp; <A class=footerLink
            id=Footer1_hlContact
            href="http://www.houseofnotes.com/Browser/Contact.aspx">Contact</A></TD>
              </TR>
              <TR>
                <TD class=footerText vAlign=center align=middle height=30>&copy; Copyright House of Notes, LLC. </TD>
              </TR>
            </TBODY>
        </TABLE></TD>
    </TR>
    <TR>
      <TD><table width="165" border="1">
        <tr>
          <td width="63"><a href="#" onClick="javascript:doPassVar('1.xml')">Link 1</a></td>
        </tr>
        <tr>
          <td><a href="#" onClick="javascript:doPassVar('2.xml')">Link 2</a> </td>
        </tr>
        <tr>
          <td><a href="#" onClick="javascript:doPassVar('3.xml')" onMouseDown="javascript:doPassVar('3.xml')">Link 3</a></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
      </table></TD>
    </TR>
  </TBODY>
</TABLE>
</body>
</html>





Here is whats in embed.js (This is to get around the change microsoft made in IE that makes the user click the flash control to activate)

function embedObject() {
      document.write('<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0\" width=\"802\" height=\"411\" name=\"flashMovie\" id=\"myFlash\">' +
      '  <param name=\"movie\" value=\"1.swf\">' +
      '  <param name=\"quality\" value=\"high\">' +
      '  <param name=\"wmode\" value=\"transparent\" />' +
      '  <embed src=\"1.swf\" name=\"flashMovie\" quality=\"high\" wmode=\"transparent\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"802\" height=\"411\"></embed>' +
      '</object>');

}

// execute!
embedObject();



Thanks for any help. To restate my problem: This is working fine in IE but not in firefox.
0
 

Author Comment

by:cwitr329
ID: 17047520
Still having problems with this. Anyone have anymore ideas?

Thanks
0
 
LVL 25

Expert Comment

by:devic
ID: 17048850
>>This is working fine in IE but not in firefox.

what says javascript console?
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to filter by key press ? 6 57
Worldmap 1 28
Asp response.write to clients 6 34
How to get text of href without any ID using Javascript 9 24
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question