The webpage you are viewing is trying to close thi

2019-05-25 21:33发布

i have a login page and if login is sucessfull,i open a homepage as popup.In IE 6.0,i dont come across a problem but IE.7.0 shows me an alert "The webpage you are viewing is trying to close this window.Do you want to close the window?".When i add the codes to hinder it,now IE 7.0 doesnt give me alert but IE 6.0 gives same problem.How can i solve this problem?

Dim strScript As String = "<script language= ""javascript"">window.open('" & Class.cls_LU_PARAMETRE.Deger("START_PAGE") & "','" & Now.ToString("ddMMyyyyHHmmss") & "','resizable=1,width=1015,height=700,left=0,top=0,scrollbars=1,status=1');</script>"
Me.RegisterStartupScript("start", strScript)

I add this code to hinder IE 7.0 warning

Dim s As String
s = "<script language= ""javascript"">"
s += " {var oMe = window.self;oMe.open('','_self',''); oMe.close();}"
s += " </script>"""
Me.Page.RegisterStartupScript("close", s)

'******************** 

5条回答
我只想做你的唯一
2楼-- · 2019-05-25 21:58

Javascript can close a window if a javascript code opens it.

Open window using javascript

<script type="text/javascript">
    function openWin(url, target, args){
        if(target && args)window.open(url, target, args);
        else if(target)window.open(url, target);
        else window.open(url);
    }
</script>
<a href="javascript:openWin('close.html');">Open window</a>
<a href="close.html" target="_self">Open window that won't close</a>

Close window using javascript

<a href="javascript:if(window.opener)window.close();">Close window</a>

It's simple, and it works in IE6, 7, 8, 9, Chrome, FF, Opera, Safari, etc... I tested it

查看更多
对你真心纯属浪费
3楼-- · 2019-05-25 22:02

You can fix this in IE by setting the self.opener property:

self.opener = this;
self.close();

EDIT: it looks like MS may have fixed this bug (it was always a bug exploit). Looks like you're out of luck unless you open the window originally yourself, and close it from the same page that opens it.

查看更多
We Are One
4楼-- · 2019-05-25 22:07

another solution

window.opener = "";
window.close();
查看更多
姐就是有狂的资本
5楼-- · 2019-05-25 22:10

It's a security feature. After all, how would you like it if some website you went to decided to close your browser window?

The most correct way to avoid this is to have opened the browser window from javascript. When you do that, the parent window is allowed to close the window without asking the user.

查看更多
地球回转人心会变
6楼-- · 2019-05-25 22:10
 function openpopup()
 {


     {
         var closeurl = "Default2.aspx";
        var popurl = "FrmUserLoginpage.aspx";
        winpops = window.open(popurl, "HMSAJAX", "toolbar=no,menubar=no, resizable=yes,status=yes,scrollbars=yes");
        window.open('', '_self', '');
        window.close();

    }

}
查看更多
登录 后发表回答