Javascript控制页面链接在新窗口打开具体方法_javascript技巧

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

第一个方法就是用jquery实现,原理是这样的先找到站点中的外部链接,然后再给链接加上target=_blank”属性就搞定了,代码如下:
jquery在新窗口打开

复制代码代码如下:

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

js在新窗口打开
复制代码代码如下:

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

html方法
在页面最新面加上
代码如下复制代码
就可以全部页面在新窗口打开
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!