Keywords: javascript, href, click, method
Not all browsers support the click Method for hyperlinks (HREF) on an HTML page.
In IE browser (more than 4.0 versions), we can use the click Method to simulate a hyperlink click action. Like what:
document. links [Somelinkindex].click ();
The click Method first triggers the element's OnClick event, or if the OnClick event returns true, continues to open the URL to which the hyperlink points.
However, in other browsers, such as Ns,firefox, it does not provide such a method. However, you can also add support for the click method to these browsers through the following JavaScript code:
<SCRIPT LANGUAGE= "JavaScript1.2">
function LinkClick () {
var executeAction = true;
if (This.onclick) {
ExecuteAction = This.onclick ({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>
<bodyONLOAD="Initlinkclick ();">
By loading prototype for the links element in onload, you can implement the Ie/ns-compatible click Method on the page:
<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>