如何在HTML、JS中重定向,如果用户关闭“;window.open()"-对话

How to redirect in HTML, JS, if user closes "window.open()" - Dialog?

本文关键字:open window 对话 quot HTML JS 用户 如果 重定向      更新时间:2023-11-01

用户点击我主页上的Download,我调用window.open(..)。如果用户按下OKCancel,我想重定向窗口!

这怎么可能?

下面是我的例子:我的主页的下载链接

你打开页面,对话框出现,你点击OkCancel,然后窗口应该重定向!

如果OK和Cancel位于新创建的窗口中,并且重定向将使用window.location ='http://....' 重定向此新窗口

如果Ok和Cancel位于主窗口中,并且重定向应使用myWin=window.open(); myWin.location='http://...' 重定向新窗口

如果"确定"answers"取消"位于新窗口中,并且重定向将重定向主窗口,则您必须从新窗口访问主窗口。

父窗口

<script language="Javascript">
    function fbLoginWindow(){
        url = "fbLogin.html"
        newwindow=window.open(url,'name','height=200,width=150');
        if (window.focus) {newwindow.focus()}
    }
</script>

<input type="button" OnClick="fbLoginWindow()" value="Login FB" />

子窗口---fbLogin.html

<script language="Javascript">
    function fbProfile(){
        window.opener.location.href="http://wwww.facebook.com";
        self.close();
    }
</script>

Allow the user to view FB Profile
<br/>Are you sure?
<input type="button" value="Ok" OnClick="fbProfile()" />