I want to disable that when you close a website it shows a message like ("Stay there and....do you really want to leave?"). How can I do it? The website is in a webbrowser, I cannot disable javascript because I need it.
Asked
Active
Viewed 1,819 times
2 Answers
1
The code "do you really want to leave?" confirmation message is triggered on the window.onbeforeunload
event. So you could add a javascript to the page which would overwrite that confirmation:
window.onbeforeunload = function () {};
To Register the javascript, use the ClientScript.RegisterClientScript
method (can be added in your Page_Load
:
Page.ClientScript.RegisterStartupScript(Me.GetType(), "BeforeUnloadScript", "window.onbeforeunload = function () {};", True);

Francis P
- 13,377
- 3
- 27
- 51
-
Can you differ the client file from the code behind file? If so, `Page_Load` should already be in your code behind file. – Francis P Oct 22 '12 at 18:58
0
if I understand correctly, this is a desktop application and you will need to inject javascript into the webbrowser control. you can either extend the existing webbrowser control, or, do something like this in document_complete: How to inject Javascript in WebBrowser control?
you need inject window.onbeforeunload if it is the function called by the popup (depends on the site you browse).