网页里很多时候会嵌入其他人的网页,但是点击的时候可能当前网页会替换成其他人的网页。
所有三叔写下这段代码,大家加到</body>前面的 <script>标签里即可。
$(function(){ $("#detaildv").find("a").each(function(a){ var href = $(this).attr("href"); if(window.document.location.host.indexOf(href)==-1 && !$(this).attr("target")){ $(this).attr("target","_blank"); $(this).attr("rel","noreferrer"); } }) })
这里需要注意两个地方。
这个方法依赖jquery
代码种的detaildv请换成阁下的代码。
其他就没有了。
测试用例: http://www.ibilibili.com/
自己玩吧。
原创申明:本文章为三叔原创。