<script>
var _b = document.getElementsByTagName('base')[0], _bH = "http://mysite.org/";
if (_b && _b.href != _bH) _b.href = _bH;
</script>
问题: 上面的代码是一个网站输出的html,这是什么意思呢?网上google了一下,但没有找到答案。
最佳答案
<base href=...>
元素用于指定解析所有相对 URL(模 @imported CSS)的基本 URL。所以通常在 <a href="foo.html">
“foo.html”被解释为与当前页面位于同一目录中的文件,但 <base href="http://othersite.com/otherpath/bar">
标签可能会导致其行为等同于 <a href="http://othersite.com/otherpath/foo.html">
如果存在 <base>
,则此脚本会设置该基本 URL标签,但没有任何效果。
这可能是导致相关链接转到 http
的误导性尝试的一部分。即使包含页面是通过 https
提供的,该网站的版本也是如此.
关于javascript - 尝试理解网站上的一些js代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16248869/