Close button on web form

R

Ron Lautmann

I want to close a browser window so I created a Close button that does this:

private void Button1_Click(object sender, System.EventArgs e)
{
RegisterClientScriptBlock("GetData","<Script>close()</Script>");
}

But when this runs the browser puts up a dialog box saying: "The web page
you are viewing is trying to close the window, od you want to close this
window?"

Is there a way to close a browser window without this dialog box?
 
I

Ignacio Machin \( .NET/ C# MVP \)

HI Ron,

No, there is no way of doing this. The only windows you can close with any
notification are the windows that your browser create.

Cheers,
 
K

Kevin Spencer

No, there is no way of doing this. The only windows you can close with
any
notification are the windows that your browser create.

Not true! The window.close() method checks to see if the opener property of
the window is null (meaning that it was not spawned by another browser
window). If you set the opener property to the window itself, it closes
without a prompt:

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

Try it!

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi Kevin,

Thanks for the tips, I had never imagined that, I think this is something
MS needs to change, it allow a rogue page to close my browser without a
warning.

I had always thought it was not possible

Thank again,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top