Javascript JS-如何在同一选项卡中打开一个url,然后在3秒钟后重定向到另一个url

Javascript JS-如何在同一选项卡中打开一个url,然后在3秒钟后重定向到另一个url,javascript,hyperlink,Javascript,Hyperlink,我对javascript有点问题 我有一个页面,这个页面是abc.com(a页面),然后我在这个页面上有一个链接,重定向到def.com(B页面),当用户点击这个链接时,我需要加载def.com页面,所以我需要这些(def.com)页面在3秒钟后重定向到ghi.com(C页面)。我试过一些密码,但我自己解决不了,有人能帮我吗 document.addEventListener("DOMContentLoaded", function twoLinks() {

我对javascript有点问题

我有一个页面,这个页面是abc.com(a页面),然后我在这个页面上有一个链接,重定向到def.com(B页面),当用户点击这个链接时,我需要加载def.com页面,所以我需要这些(def.com)页面在3秒钟后重定向到ghi.com(C页面)。我试过一些密码,但我自己解决不了,有人能帮我吗

 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页,因此,我无法打开重定向链接。

在abc.com中这样说

<a href="def.com" >Abc page </a>
 setTimeout(function(){ window.location.replace("ghi.com"); }, 3000);
这是一个非常肮脏的代码-你可以用bat托盘

<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>

函数changeUrl(){
让site=“def.com”;
document.getElementsByName('cake')[0].src=site;
让frame=document.getElementById(“itest”);
frame.style.display='';
let button=document.getElementById(“btest”);
button.style.display='none';
setTimeout(function(){window.location.replace(“ghi.com”);},3000);
}
加载def.com

我忘了说,我无法控制def.com,但谢谢我的朋友!这回答了你的问题吗?在现有选项卡中,您将根本无法实现这一点-加载def.com后,您自己的代码将完全消失,您将无法访问或控制该选项卡。如果有什么问题的话,如果您打开一个新选项卡并保留对它的引用(window.open),那么您仍然可以从外部为该选项卡设置一个要导航到的新URL。