Home > Web Front-end > JS Tutorial > body text

Javascript controls how to open a page link in a new window_javascript skills

WBOY
Release: 2016-05-16 17:25:26
Original
1282 people have browsed it

The first method is to use jquery to implement it. The principle is to first find the external link in the site, and then add the target=_blank" attribute to the link. The code is as follows:
jquery opens in a new window

Copy code The code is as follows:

$("a[href*='http://'] :not([href*='" location.hostname "']),[href*='https://']:not([href*='" location.hostname "'])")
. addClass("external")
.attr("target","_blank");

js opens in a new window
Copy the code The code is as follows:

var aTag = document.getElementsByTagName('a');
for(i in aTag){
aTag[ i].target='_blank';
}

html method
Add
to the latest page of the page. Copy the code as followsYou can open all pages in a new window
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