设定目标=外部链接和标准
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了设定目标=外部链接和标准相关的知识,希望对你有一定的参考价值。
If you want your pages to be valid Xhtml-Strict, but you also wish to open external links in new window, the following snippet is doing just that—sets attribute target=“_blank†to all external links in a document to keep your code valid XHTML-Strict. You’ll just have to change variable yourURL. Don’t enter http://www. part of your domain, otherwise something like http://sample.com/ will be treated like any other external link.
// change your domain name: var yourURL = "sample.com"; function outLinks() { var outLink; if (document.getElementsByTagName('a')) { for (var i = 0; (outLink = document.getElementsByTagName('a')[i]); i++) { if (outLink.href.indexOf(yourURL) == -1) { outLink.setAttribute('target', '_blank'); } } } } window.onload = function() { outLinks(); }
以上是关于设定目标=外部链接和标准的主要内容,如果未能解决你的问题,请参考以下文章
Android - 使用外部浏览器在 WebView 中打开目标 _blank 链接