我对 javascript 有一个小问题。
我有一个页面,这个页面是 abc.com(页面 A)然后我在这个页面有一个链接,重定向到 def.com(页面 B),当用户点击这个链接,我需要加载页面 def.com,所以我需要这些 (def.com) 页面重定向到 ghi.com(页面C) 3 秒后。我尝试了一些代码,但我无法自己解决,有人可以帮助我吗?
document.addEventListener("DOMContentLoaded", function twoLinks() {
myTab = document.getElementById("redirect").onclick = setTimeout(function () {
document.getElementById("redirect").href = "http://www.def.com";
}, 1000);
if(myTab){
setTimeout(function(){
window.location('http://www.ghi.com/');
}, 3000);
}
});
提前致谢!
编辑:我需要的是当用户点击页面 A 中的链接时,浏览器加载页面 B,3 秒后它们被重定向到页面 C,所有页面都在同一个选项卡上,但我没有访问页面 B 或页面 C 所以,我不能把重定向链接放在那里。
答案 0 :(得分:0)
在 abc.com 中放这个
<a href="def.com" >Abc page </a>
在 def.com 上放这个
setTimeout(function(){ window.location.replace("ghi.com"); }, 3000);
这是非常脏的代码 - 蝙蝠你可以托盘
<html>
<head>
<script type="text/javascript">
function changeUrl() {
let site = "def.com";
document.getElementsByName('cake')[0].src = site;
let frame = document.getElementById("itest");
frame.style.display = '';
let button = document.getElementById("btest");
button.style.display = 'none';
setTimeout(function(){ window.location.replace("ghi.com"); }, 3000);
}
</script>
</head>
<body>
<center>
<button id="btest" onclick="changeUrl()">Load def.com</button>
<div>
<iframe id="itest" src="" height="100%" width="100%" frameborder=0 name = "cake" style ="display:none"></></iframe>
</div>
</center>
</body>