当我转到下一个 URL 时,警报不起作用。我需要在窗口位置 onchange 上每 3 分钟获取一次窗口 href 值。
var i=0;
function load(){
var currentLoc = window.location.href;
PrevLoc = currentLoc;
interval(currentLoc,PrevLoc);
}
function interval(currentLoc,PrevLoc){
setInterval(function () {
if(currentLoc == 'https://github.com/features'){
alert('Reached the Target Page')
// document.write('Reached the Target Page');
return true;
}
if(currentLoc == PrevLoc){
alert(window.location.href);
// document.write(window.location.href);
if(i==0){
PrevLoc = window.location.href;
window.location.href = "https://github.com/join?source=login";
currentLoc=window.location.href;
}
interval(currentLoc,PrevLoc);
i++;
}
else {
alert(window.location.href);
// document.write(window.location.href);
}
},3000);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script>
<body onLoad="load();">
</body>
我正在使用 setInterval 使用 javascript 和 jquery 尝试此操作。但当更改 href 值时,它不起作用。
<html>
<head>
</head>
<body onLoad="load();">
<script>
function load(){
window.location.href = "https://github.com/join?source=login"
var PrevLoc = "https://github.com/join?source=login";
var currentLoc = window.location.href;
if(currentLoc == PrevLoc){
alert('inside')
setInterval(function () {
alert('changed')
},3000);
}
else {
}
}
</script>
</body>
</html>
最佳答案
更改此:
if(currentLoc == PrevLoc){
alert('inside')
setInterval(function () {
alert('changed')
},3000);
}
对此或您想要检查的任何内容:
setInterval(function () {
if(currentLoc != PrevLoc){
alert('changed')
}
},3000);
关于javascript - 如何知道每 3 分钟的窗口 href 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44822673/