Links (HREF elements), click method
Keyword: javascript, href, click, the method
For HTML pages on the hyperlinks (HREF), not all browsers support its click method.In the IE browser (version 4.0 and above), we can use the method to simulate a click hyperlinks click operation. For example:
Document.links [someLinkIndex]. Click ();
First click method trigger elements onclick events; return true if onclick events will continue to open the hyperlink pointing URL.
But in other browsers (such as NS, firefox, etc.), does not provide such a method. But you can be the adoption of the following javascript code for the browser has also increased click on the methods of support:
<SCRIPT LANGUAGE="JavaScript1.2">
Function linkClick () (
Var executeAction = true;
If (this.onclick) (
This.onclick executeAction = ((type: 'click'));
)
If (executeAction)
Open (this.href, this.target? This.target: '_self');
)
Function initLinkClick () (
If (document.layers & document.links.length> 0)
Document.links [0]. Constructor.prototype.click = linkClick;
) </ SCRIPT>
</ HEAD>
<BODY ONLOAD="initLinkClick();">
By the time the links onload elements loaded prototype, you can achieve pages in IE / NS compatible click:
<A HREF= http://www.webjx.com/ ONCLICK="alert(event.type); return true;">
Link1 </ A>
| <A HREF= http://www.webjx.com/ TARGET="_blank">
Link2 </ A>
| <A HREF = "http://www.webjx.com" ONCLICK = "alert (event.type); return
False ">
Link3 </ A>
|
<BR> <FORM> <INPUT TYPE = "button" VALUE = "link1 click"
ONCLICK = "document.links [0]. Click ();">< INPUT TYPE =" button "VALUE =" link2 click "
ONCLICK = "document.links [1]. Click ();">< INPUT TYPE =" button "VALUE =" link3 click "
ONCLICK = "document.links [2]. Click ();"></ FORM>
Tags: xhtml elements xhtml source






Leave a Reply