下面的代码仅显示<span>
上http://example.com/但不会显示<span>
上http://example.com/files/target.html那么如何让它在具有指定域的所有页面上工作呢?请帮忙。
<script type="text/javascript">
var myurl = "http://example.com/";
var currenturl = window.location
if(myurl != currenturl) {
$("<span style=font-size:200px;>big</span>").replaceAll("body"); // check replaceWith() examples
}
</script>
最佳答案
这应该有效:
<script type="text/javascript">
var myurl = "www.myurl.com";
var currenturl = window.location.hostname;
if(myurl != currenturl) {
$("<span style=font-size:200px;>big</span>").replaceAll("body"); // check replaceWith() examples
}
</script>
关于javascript - 如果指定的域不等于,则当前 URL 应用此 jQuery 以及具有相同域的页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7629640/