|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to simulate click action in N6?
I'm trying to simulate a click action upon completion of some tasks, so as to bring user back to the default page. The following codes work in IE5.5+, but not in N6+, what could be the problem? Is .click() supported in N6+?
function setDefaultPage() { simulateAnchorClick(document.anchors[0]); } function simulateAnchorClick(anchor) { anchor.click(); } |
|
#2
|
|||
|
|||
|
It's a bug in Mozilla. click() works for a number of form elements, but not yet for anchors.
Here's a workaround: location.href = anchor.href Hope this helps, Jeroen |
|
#3
|
|||
|
|||
|
Not a bug:
http://www.w3.org/TR/2003/REC-DOM-L...tml#ID-48250443 See a click() method anywhere? Didn't think so. However, because Mozilla has such excellent standards support, you can give anchors a click method yourself: HTMLAnchorElement.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); } |
|
#4
|
|||
|
|||
|
Jerom and jkd, I'm so grateful for your replies. Somehow I missed your replies till now
![]() I like both ideas However, I'm not quite sure how to implement them...1) Jerom Do you have sample codes with reference to my example above? 2) jkd Where can I put that piece of code in? How to call/use it? A little lost here. |
|
#5
|
|||
|
|||
|
The solution posted by jkd is superb. Use it!
You just need to make sure that any Mozilla based browser loads his code before using any anchor based click method. Jeroen |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > How to simulate click action in N6? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|