我想检查浏览器中的URL是否包含单词“Desktop”(我从桌面启动了HTML文件)。它的URL是:"file:///C:/Users/Joe/Desktop/TestAlert.html"
但是,应该出现警报,但这不起作用。
这是我的代码:
<html>
<head>
<script type="text/javascript">
$(document).ready(function () {
if(window.location.href.contains("Desktop") > -1) {
alert("Alert: Desktop!");
}
});
</script>
</head>
<body>
<h1>Test001</h1>
</body>
</html>
我在Firefox, Chrome和Internet Explorer中测试过这个。 如果有人能帮忙,那会非常好!