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

时间:2016-03-31 13:38:39

标签: javascript html

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

这怎么可能?

以下是我的例子: A Download-Link of my Homepage

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

2 个答案:

答案 0 :(得分:0)

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

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

如果Ok和Cancel驻留在新窗口中,重定向将重定向主窗口,则必须从新窗口访问主窗口。

答案 1 :(得分:0)

父窗口

<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()" />