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

Summary of methods to open hyperlinks in new windows_javascript techniques

WBOY
Release: 2016-05-16 17:37:10
Original
1761 people have browsed it
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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template