locked
Unable to close web page RRS feed

  • Question

  • User1769015664 posted

    I have tried the following methods to close the page but none of these methods have worked. How do I close it?

    ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.open('close.html', '_self', null);", true);

    ClientScript.RegisterStartupScript(typeof(Page), "closePage", "window.close();", true);
    ContinueButton.Attributes.Add("onclick", " CloseWindow();");


     this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);

    string strScript = "window.close();";
    ScriptManager.RegisterStartupScript(this, typeof(string), "key", strScript, true);

    Friday, May 22, 2020 9:24 AM

All replies

  • User475983607 posted

    The same code that opened the window must close the window.  You'll need to change your approach.

    https://developer.mozilla.org/en-US/docs/Web/API/Window/close

    Friday, May 22, 2020 10:48 AM
  • User1769015664 posted

    I have reviewed the article, has helpful information but no resolution to my issue.

    When Login's Registration page I submit, the login's Registration Confirmation page doesn't come up. So, I created a new .aspx page and used Response.redirect to display it when Registration was successfully completed.

    I need to find a way to close it instead of clicking on "X" button on the top right corner.

    Friday, May 22, 2020 3:54 PM
  • User475983607 posted

    I have reviewed the article, has helpful information but no resolution to my issue.

    When Login's Registration page I submit, the login's Registration Confirmation page doesn't come up. So, I created a new .aspx page and used Response.redirect to display it when Registration was successfully completed.

    I need to find a way to close it instead of clicking on "X" button on the top right corner.

    The rule is very simple.  The JavaScript code that opened the window is the only code that can also close the window.  It is up to you to write code that follows the rules.  Perhaps use  modal rather than a window then the rule no longer applies. 

    Friday, May 22, 2020 4:07 PM
  • User753101303 posted

    Hi,

    My understanding is that you had something that didn't worked as eppected and came up with a solution causing to have this need. If confirmed, it would be better to solve your source issue.

    As previously explained,  to keep the user safe and in control, those conditions needs to be met for using window.close : https://html.spec.whatwg.org/multipage/window-object.html#dom-window-close (for example an attacker coudl prevent any access to your site by closing the window/tab or use that to close ans show a phising site after some inactivity etc...).

    Edit: copy/pasted as the fragment doesn't seems to work:

    The <dfn id="dom-window-close">close()</dfn> method must run these steps:

    1. Let <var>current</var> be this Window object's browsing context.

    2. If <var>current</var> is null or its is closing is true, then return.

    3. If all the following are true

      then:

      1. Set <var>current</var>'s is closing to true.

      2. Queue a task on the DOM manipulation task source to close <var>current</var>.

    A browsing context is <dfn id="script-closable">script-closable</dfn> if it is an auxiliary browsing context that was created by a script (as opposed to by an action of the user), or if it is a top-level browsing context whose session history contains only one Document.

    Friday, May 22, 2020 6:22 PM