Home  >  Article  >  Web Front-end  >  Summary of methods to open hyperlinks in new windows_javascript techniques

Summary of methods to open hyperlinks in new windows_javascript techniques

WBOY
WBOYOriginal
2016-05-16 17:37:101748browse
First, let all the links in the entire web page open in a new window: add

in the head

2 Let all links in a DIV open in a new window:

Add

into the body Copy code The code is as follows:




Added whether to specifically ask the current window to open
Copy code The code is as follows:

 //Control the hyperlink to open in a new window
 var tar="";
tar="_blank ";
 var urls=document.getElementsByTagName("a");
 for (var i=0;i
 {
 if(urls[i].target!="_self"){
URLs[i].target=tar;
 }
 }

Let the specified link open in a new window:

Open in original window: Baidu
Open in new window:: Baidu
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn