This code is written by oneself practicing to help others solve a problem.
The requirement is this:
<a href= "Http://www.jb51.net/article/window.open (", ")" >test</a>, this can not change, only to do things outside, how about it?
Request to click on the above connection, open a new page, and other actions on the original page.
Analysis: The above open a new page of the writing itself is wrong, can not open a new page. The correct wording should be:
<a href= "javascript:void (0)" onclick= "Http://www.jb51.net/article/window.open (", ")" >test</a>
So the solution is to use external JS to modify the content of the connection. The first thing to determine is that the href attribute inside the link contains "window.open" and then adds the onclick attribute to it and assigns the href content to it. Then modify the href attribute content.
But the solution found a problem, read the HREF attribute content can not get its actual content, but the Web page URL path (remove the last page file name) +href content, but also to the previous URL path removed. This can be solved with substring () combined with indexof ().
As for the original page, some content is much simpler.
According to the analysis, write the following test code to achieve the above requirements:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd "> <ptml xmlns =" http://www.w3.org/1999/xhtml "Xml:lang =" en "lang =" en "> <pead> <title>< /title> <script type = "Text/javascript" > Function addevent (elm,evtype,fn,usecapture) {if (Elm.adde Ventlistener) {Elm.addeventlistener (evtype,fn,usecapture); return true; }else if (elm.attachevent) {var r=elm.attachevent ("on" +EVTYPE,FN); return R; }else{alert ("Handler could not to be removed"); }} function DoOther () {if (event.srcelement.tagname== "A" && event.srcElement.getAttribute ("href"). In Dexof ("window.open")!=-1) {Event.srcElement.setAttribute ("onclick"), Eval (event.srcElement.href.substring ( Event.srcElement.href.lastIndexOf ("/") +1,event.srcelement.href.length)); Event.srcElement.setAttribute ("href", "javascript:void (0)"); document.getElementById ("Test"). Innerhtml= "<font color= #ff0000 ><b> is it like this? </b></font> "}} addevent (document," click ", DoOther); </script> </pead> <body> Test, this does not change, can only do things outside, how about it? <div id= "Test" ></div> </body> </ptml>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]