PDA

View Full Version : Help! Code works in IE not in FireFox


srk
05-23-2005, 09:09 PM
Hi!

I have a piece of code to accomplish the following:

When I tab to first cell of the Table and press spacebar, the click event should be triggered and alert message should pop up.

It works fine in IE but not in FireFox. Please suggest what I am doing wrong?
In FireFox, Javascript console shows the following error:

thisEl.click() is not a function.

My Code:
----------------------------------------------------------------------
<HTML DIR=LTR>
<HEAD>
</HEAD>
<BODY>
<TABLE BORDER=1>
<TR>
<TD id = 'R1C1' onkeydown="checkKey(event)"; onClick="alert('Test1-a')";><a href=#>Test1-a</a></TD>
<TD><a href=#>Test2-a</a></TD>
<TD><a href=#>Test3-a</a></TD>
</TR>
<TR>
<TD><a href=#>Test1-b</a></TD>
<TD><a href=#>Test2-b</a></TD>
<TD><a href=#>Test3-b</a></TD>
</TR>
<TR>
<TD><a href=#>Test1-c</a></TD>
<TD><a href=#>Test2-c</a></TD>
<TD><a href=#>Test3-c</a></TD>
</TR>
</TABLE>
<SCRIPT>
var thisEvt = null;
var thisEl= null;
var ie4 = (navigator.appName.indexOf("Internet Explorer") !=-1) ? true: false;
function checkKey(evt){
if (!ie4) {
thisEvt = evt ;
thisEl=thisEvt.target ;
} else { thisEvt = window.event ; thisEl=thisEvt.srcElement ; }
if(thisEvt.keyCode==32){
thisEl.click();
}
}
</SCRIPT>
</BODY>
</HTML>

----------------------------------------------------------------------


Please help,

SRK

jkd
05-23-2005, 09:52 PM
http://www.codingforums.com/showpost.php?p=34595&postcount=5

Include that snippet somewhere on your page.

srk
05-23-2005, 10:28 PM
Thank you jkd. It works now on FireFox. It looks like I need to put the recommended code snippet inside

if(!ie)
{//code snippet//}

Thanks again
srk

srk
05-24-2005, 01:18 AM
Hi jkd,

I am still having problems even if I use the code snippet, when there are multiple controls on a page. How do I add the code snippet when there are multiple controls?

please help,

Thank you,
srk

jkd
05-24-2005, 03:12 AM
Once it is executed, every element has a click() method in Firefox. So, stick it in *once*, inside an if statement that only is true in Firefox.

srk
05-24-2005, 06:20 PM
Thank you very much jkd, It works now.

srk

srk
05-25-2005, 04:50 PM
Hi jkd,

Do I have to do something similar for doubleclick?
I am seeing the same error thisEl.dbkclick() is not a function.
when I add a doubleclick event.

Thank you,
srk

jkd
05-25-2005, 08:17 PM
Well, IE doesn't have that method either. If you're only concerned about Firefox, then replace click with dblclick whereever you see it in that code.

srk
05-25-2005, 08:50 PM
Thank you jkd,

When I changed click to dblclick in your code snippet, FF recognizes dblclick event. But you are right, looks like IE doesn't support dblclick. I am getting the error "object doesn't support this property or method". Are there any workarounds for this problem?

I really appreciate your help.

srk

jkd
05-26-2005, 01:35 AM
Research the fireEvent() method at www.msdn.microsoft.com. Pretty sure IE has that.

srk
05-26-2005, 04:52 PM
Thank you jkd! You are Super..

It worked!!. I was able to do thisEl.fireEvent('ondblClick') to trigger the dblclick event in IE.


Thanks again,
srk

tinuverma
08-11-2006, 08:08 PM
Hi JKD,
I tried to use your code in my application, but it didnt help. Basically i am copying and pasting your code in my html page..I put an alert box to tell me when it was called...and the alert never got called.

HTMLElement.prototype.click = function() {
alert('called');
var evt = this.document.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.document.defaultView, 1, 0, 0 , 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);
}

I put this line of code in head and as last part of the body code (ofcourse in <script> )...nothing happened...please help!

urpalshu
02-26-2010, 09:43 PM
How would I make it execute just once.

Once it is executed, every element has a click() method in Firefox. So, stick it in *once*, inside an if statement that only is true in Firefox.

Thanks,
urpalshu

toldigabor
04-19-2011, 05:26 PM
I have a website, where there is a search form. This work with POST and there is pagination. When I pagination filled the form by a javascript script (page in a hidden item, search string in a text item). When I click the 'Next' or 'Back' link, start a script: page-1 or page+1 in the hidden item and form_name.submit_button_name.click()
This is in IE is perfect, but in Firefox not working.
I paste your code in a other separate .js file, but attach for the php file:

if (navigator.appName != "Microsoft Internet Explorer")
HTMLElement.prototype.click = function() {
var evt = this.ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
this.dispatchEvent(evt);


But the Firefox doesn't working. Why? Please, answer my question. Thank you

http://www.codingforums.com/showpost.php?p=34595&postcount=5

Include that snippet somewhere on your page.