We help IT Professionals succeed at work.

Onclick not working in firefox but does in IE

cwitr329
cwitr329 asked
on
4,161 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
Comment
Watch Question

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.

Commented:
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>
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

Author

Commented:
Thank guys, gave both of the suggestions above a try and still nothing... I click on it and its not executed. Anymore ideas?
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.

Author

Commented:
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
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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.
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 :-)
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
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

Author

Commented:
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>
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?

Commented:
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);    
}

Commented:
or use the getFlashMovieObject function on the link provided by CyberGhost.
Michel PlungjanIT Expert
CERTIFIED EXPERT
Top Expert 2009

Commented:
@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
CERTIFIED EXPERT

Commented:
<a href="http://www.google.com/search?q=" onclick="this.href+='always coca cola';">never say never ;)</a>
IT Expert
CERTIFIED EXPERT
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
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.

Author

Commented:
Still having problems with this. Anyone have anymore ideas?

Thanks
CERTIFIED EXPERT

Commented:
>>This is working fine in IE but not in firefox.

what says javascript console?
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.