Solved

Onclick not working in firefox but does in IE

Posted on 2006-06-19
19
4,035 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
  • 5
  • 5
  • 4
  • +2
19 Comments
 
LVL 6

Expert Comment

by:CyberGhost
Comment Utility
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
Comment Utility
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
Comment Utility
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
 

Author Comment

by:cwitr329
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:cwitr329
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
or use the getFlashMovieObject function on the link provided by CyberGhost.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
@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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
Still having problems with this. Anyone have anymore ideas?

Thanks
0
 
LVL 25

Expert Comment

by:devic
Comment Utility
>>This is working fine in IE but not in firefox.

what says javascript console?
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now