Is it at all possible to disable the "The webpage you are viewing is trying to close the window. Do you want to close it?"?
I understand that this is the product of years of virus, and malicious script activity, but in legit app code, (ASP.NET), is there any way to like "register" your app as an APP, or flags you can pass to an IE Popup so that it will not display this when it closes?
The code I'm using is done from within the C# code behind:
ClientScript.RegisterClientScriptBlock(GetType(), "save", Utils.MakeScriptBlock("window.close();"));
The Utils.MakeScriptBlock is just a function that does what you might expect. It 'injects' a <script...> tag with the code in it...
It's probably not possible to get around this, or else, all the script kiddies would just use that trick, but I thought I'd ask, as I can't be the ONLY one using simple IE "popups" as (pseudo)modal dialog boxes.
This code happens in my ButtonSave_Click() routine, after everything has passed validation, etc...
** EDIT **
Just for reference, here is the code that OPENS the popup, when the ADD button is clicked:
This is in Page_Init()...
ButtonAdd.Attributes.Add("onclick", "window.open('Add.aspx', 'ADD_WINDOW', 'scrollbars=no,width=550,height=550,location=no,menubar=no,resizable=yes,directories=no,status=no,toolbar=no'); return false;");
You can close the window without the popup if the window was opened by your script. Does that help?
Edit:
You're already opening the window with script. Change your client script to call self.close().
ClientScript.RegisterClientScriptBlock(GetType(), "save", Utils.MakeScriptBlock("self.close();"));
I believe not. As you state to help prevent malware.
In the end the browser does not know that you are not evil. See RFC 3514 for a similar idea.
I highly doubt it's possible on your end - sounds like something a user would have to specifically disable in their IE settings.
If the user opened the browser window, you can't close it; but if the window was opened via script, you can. Sounds like you just need an initial page that the user starts at with a "click here to begin" link, from which you open a new window for the main portion of the site; when they're all done, close the popup and they're left with their initial browser window with the "click here to begin" message.
Bizarre, but I've found that
<script type="text/javascript">
function closeWindow()
{
window.close();
return false;
}
</script>
and then calling
return closeWindow();
usually gets around this.
Related
I've been searching for an answer to this but haven't found what I'm looking for yet.
When I load into the page there is a check run one the server side. Depending on the output of this (bool), I wish to display a "yes no" confirm box to execute another piece of server side code.
I have found ways to do this easily enough on a button click but I'm trying to avoid adding a hidden button and simulating a click.
MessageBox.Show isn't an option in this case as I get the following error:
Showing a modal dialog box or form when the application is not running
in UserInteractive mode is not a valid operation
Is there any way to achieve this without simulating a button click?
Cheers,
Spitfire2k6
In web app (including the one created with ASP.NET) you can use Javascript confirmation dialog box: window.confirm("Request to Confirm Text");, and process User's response like in the following sample code snippet:
var _response = confirm("Please Confirm");
if (_response == true) {//Do Action1}
else {//Do Action1}
Pertinent to your case, you can use for e.g. page <body onload> event. Hope this may help.
I realised I was going about this all wrong.
The check is now done on page load, depending on the result I'm showing an asp panel with 2 asp buttons as a confirm box.
Thanks for all guidance.
Cheers,
Spitfire2k6
I have an application that uses WebBrowser control to navigate from page to page, on some pages I get a leaving popup asking me if that's what I want to do.. this stops the whole further execution until I press "Leave" or "Stay".. How can I disable them?
What I've tried so far were these actions:
a) setting window.onbeforeunload = null;
b) setting alert, confirm, prompt to an empty function
c) settin suppressErrorMessages to true
but even so, I still get the nasty message in the end.
I mostly relied on this answer:
How to update DOM content inside WebBrowser Control in C#?
But so far without a success.
The alerts seem to be jQuery alerts because they have custom texts (instead of OK Cancel, they have Stay Leave)..
Any help hugely appreciated!!
The webbrowser control uses IE internally and IE has a prompt if you've filled out a form asking you if you really want to leave the page (thereby losing the content you've filled out) perhaps that's what you're seeing?
i'm just shooting from the hip here but you could try clearing all inputs before navigating.
Does anybody know how to open an URL in a new tab from C# code?
I have tried with
Response.Write("<script type='text/javascript'>window.location.href('../Documents/doc.pdf','_blank'); </script>");
Response.Write("<script type='text/javascript'>window.open('../Documents/doc.pdf','_blank'); </script>");
Response.Write("$('#pageContent_Send').click();");
with
$("#pageContent_Send").click(function () {
window.open("../Documents/doc.pdf");
return false;
});
and it did not work, using "window.open" I get an "Pop-up Blocker" browser warning.
There are a few options for opening a new tab that won't get blocked.
You can have it open the URL with an anchor click, like so click me
You can submit a form to a blank target, giving a similar result, but from a form. This is useful if you need to post, but can also be useful for get. Like so <form method="get" action="<your destination>" target="_blank"><button type="submit">Click Me</button></form>
You can use JS with window.open but it has to be tied to an active click event. I see in your original post that this got blocked, but if you're triggering it on a click event directly (i.e. not using a setTimeout or an async call or something else that delays the window opening) then this should work in all browsers. Since you're trying to "fake" it by forcing a click, the browser is going to block this every time unless you explicitly allow it.
<a href='www.xyz.com' target='_blank'>Click me to open me in new tab</a>
I have a web page that contains a textbox and a submit button. When the user edits the text in the textbox and clicks another link (not the submit button) how do I display the 'Are you sure you want to navigate away from this page' popup message?
I have researched this on the net and found a few javascript examples. Is this the only way you can do this? If not, what is the best way to do it?
This is one of the multiple ways to achieve the same thing
function goodbye(e) {
if(!e) e = window.event;
//e.cancelBubble is supported by IE - this will kill the bubbling process.
e.cancelBubble = true;
e.returnValue = 'You sure you want to leave?'; //This is displayed on the dialog
//e.stopPropagation works in Firefox.
if (e.stopPropagation) {
e.stopPropagation();
e.preventDefault();
}
}
window.onbeforeunload=goodbye;
got it from here open js
Only the unload() event will work on JS. You can't manage it on the server.
Check out the answer to this other question on SO, it is very similar to your question
How to show the "Are you sure you want to navigate away from this page?" when changes committed?
Simple solution
window.onbeforeunload = confirmExit;
function confirmExit() {
return "Are you sure you want to leave this page?";
}
4guysFromRolla.com - Prompting a user to Save when Leaving a Page
You cannot use the onbeforeunload window method as it gets triggered by multiple ways like back and forth browser navigation links, refreshing the page, closing of the page, clicking on the links.
What i feel you have to bind the link tag for which you want display the navigation away message and then use the function for the status message display
window.addEvent('domready',function(){
$$('a').addEvent('click', function(e) {
//leaving(); function u wrote for displaying message
});
});
function leaving(e) {
if(!e)
e = window.event;
// return code for the displaying message
}
If you want to do this in a way that guarantees it will work on almost all browsers, use the JQuery library. The following describes the unload event.
http://www.w3schools.com/jquery/event_unload.asp
It's exactly for purposes like yours.
Just to elaborate a little, you would have to download the jquery js library and reference it in your project/page, but you'll probably want to do that eventually anyway.
If you want to control this from the server side, you can dynamically emit the jquery call in the OnPreRender.
Look into Jquery's .beforeunload property. Here is an example:
$(window).bind('beforeunload', function(){ return 'Click OK to exit'; });
Please note, beforeunload canot prevent a page from unloading or redirect it to another page for obvious reasons; it would be too easy to abuse. Also if you just want to run a function before unloading, try the following:
$(window).unload(function(){ alert('Bye.'); });
Finally, don't forget to referrence jQuery in your head tag by using:
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
The above gets you the latest version from the internet and saves you the trouble to download it, and of course you can do so optionally, but I am just trying to get your thing to work asap.
Oh, I also found an example for you. Click here to see a page that calls a function before it closes. Hope this helps bud.
I was able to get this to work with Andrei G's answer. I would add on that to get it to work in Chrome, add this to the end of his goodbye function:
return "";
There's no easy way to explain this but, I have a website, that links to a online game I've made using asp C#. The website has a link to the game so when the user clicks the link on the site, my game pops up! Simples...
But I want it to pop up in a new Window! but not a browser window... Just... A Window :s
for Example, if you go on www.dofutoshiki.com and click on the "Play Futoshiki in our online player" link, it opens a new window with, just the game. No browser functionality.
I was wondering if anybody out there could shed some light on the subject...
Ive Tried:
Click me!
but it just opens a new tab in the browser!
Thanks!
Alex
If I get this right, you actually want a browser window but without the chrome/UI.
For this, you need to use window.open() (javascript) rather than a target attribute.
http://www.pageresource.com/jscript/jwinopen.htm will help you.
You have to open the new window by using javascript and disabling the unwanted functionality by passing arguments.
You will probably need some javascript for this. What you need to look in to is the
'window.open(...)' function.
Here are a few examples.
And here you can play around with it.
Use javascript Window.open method
Click me!
<script>
function openGame(){
window.open(blahblah.aspx,'Play Game','width=900,height=790,scrollbars=yes,dependent=yes,toolbar=no,location=no,status=no,directories=n o,menubar=no,status=no,resizable=yes');
}
</script>
You can use Jquery popup window plugin it is easy to use and more flexible also.
http://swip.codylindley.com/popupWindowDemo.html
On site you are referring to, browser window is opened. It's configured so that it does not have toolbar, status bar, menu bar, etc.
You can take a look at window opening code in HTML source of the page you are referring to:
<a onClick="window.open(this,'playsample','width=900,height=790,scrollbars=yes,dependent=yes,toolbar=no,location=no,status=no,directories=no,menubar=no,status=no,resizable=yes');return false;">
Is javascript an option?
With javascript it would be something like this:
<a href="#" onclick="window.open('blahblah.aspx', 'game','status=0,toolbar=0,width:400,height:300');" > Click here for the game! </a>
Use this
Click me!
Or even better, put the onclick code in a function of your own so you can reuse it.