简体   繁体   中英

How can I tell if my page was opened using Window.Open()

I have an EventDetails.aspx page with details for an event which can be opened by my user using Window.Open() from my Timetable.aspx page. On the EventDetails.aspx page I have a button that allows me to then close the window using the following code:

protected void CloseWindow_Click(object sender, EventArgs eventArgs)
{
    Response.Write("<script language='javascript'>window.open('','_self');window.close();</script>");
}

When I open my window with Window.Open() from the Timetable.aspx page the close window button works fine, however if I navigate independently to the EventDetails.aspx page I am unable to use the close window button - nothing happens!

Is there a way I can determine if the user has navigated using Window.Open() so that I can change the visibility of my button, or better still, is there another way I can close my tab that does not rely on using Window.Open()?

You Can Pass data to opened window so that in opened windows you can make check in js for that data and you can hide or show buttons according to data passed

// Store the return of the `open` command in a variable
var newWindow = window.open('example.com','_self');

// Access it using its variable
newWindow.my_special_setting = "Hello World";

In Opened Window you can check data like code below

window.my_special_setting

Added A Jquery Fiddle To Confirm that it will work with '_self'

 <!DOCTYPE html> <html> <body> <p>Click the button to open a new browser window.</p> <button onclick="myFunction()">Try it</button> <script> window.open("http://www.w3schools.com","_self"); </script> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM