Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic link click in Mozilla

Status
Not open for further replies.

Pichdude

Programmer
Aug 24, 2005
66
0
0
SE
Hi, I use this javascript to force a link click once the page is loaded.

document.getElementById('theLink').click();

But this only work in IE, does anybody know of a solution that also works for Mozilla?

Regards

Pichdude
 
click() is not a supported method on firefox. However, you can set up a custom prototype method to make it work. Just include this code somewhere on your page:
Code:
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);
}

Here's a reference to where this can be found:


-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top