How to avoid the confirm dialog box “the web page you are viewing is trying to close the window” when trying to close IE popup?
Make sure the window you are trying to close is one you opened with JavaScript, and not the one the user arrived at your site with (complete with history they might want to go back through).
This hack used to work in IE, but not sure if it still does:
window.opener = window;
window.close();
Related
I am using angularjs.I have link suppose open tab now user right clicks on link and selects open link in new tab ,Now i have code in page abc.html like $window.close();.It is not working as expected i am getting Following Error Scripts may close only the windows that were opened by it.I googled on that i found only browser windows created using JavaScript can be closed using JavaScript.is there any way i can acheive my goal.
Thanks
If the user has chosen to open it in a new tab, you can't close it with JavaScript. However, if you use window.open(), you can close the opened window using JavaScript.
So the answer is no, unless you hack the user's computer.
It is possible.
try this:
window.top.close();
Working for me on all three major browsers.
if it does not work try :
open(location, '_self').close();
I have this solution that takes the user through a series of questions. At the end the user can click a button that opens a new window with a form to enter contact info. The population of this popup window is done through JavaScript from the calling window.
The process (in JS) is this:
Open popup window with loading gif
Store additional information remotely through ajax
Populate popup window with contact form
This all works fine in desktop browsers but not on iPads (using Safari where all windows are displayed as tabs). I have a suspicion that the JavaScript in the parent tab is halted when the "popup" tab gets displayed. To support this theory I can actually get the popup tab populated if I switch back to the parent tab immediately after the popup tab is displayed.
Can anyone confirm this? And of course if there's a solution I would very much like to hear about it.
Needless to say it works like a charm on my Android tablet :-)
Try using window focus and blur to activate some javascript when the focus is back on your tab.
See: https://stackoverflow.com/a/3479936/1712686
The reading of this Avoid browser popup blockers confirm my feelings that add blocker does simply allow popup that are opened by a user generated event.
I'm using dhtmlxgrid and get notified from a user click over one cell through the "onRowSelect" event but calling raise a problem with Firefox and Chrome ad blocker :
window.open(url, "_blank");
Any idea or magic solutions.
Are you using the Dhtmlx Window component? because that call window.open() is pure JS call.
You may try to create a DhtmlxWindow object that is a DIV and it should not be blocked, I used this before and never got problems.
Here's a simple INIT guide to use dhtmlx Window.
http://dhtmlx.com/docs/products/dhtmlxWindows/samples/01_init/01_minimal_init.html
when i try to
window.open()
in IE 9 , it opens it with favorites sidebar (if it was present in parent window) this is behaviour unique to IE , and it breaks dialog windows as I envisioned them. Any hope to fix that?
Since you specified that you're using this for a dialog, I feel I should discourage this. Using window.open() is not ideal for creating dialog boxes.
Some browsers will ignore your 'new window' request, and open it as a new tab. This can be configured by the browser user, so is out of your control.
If the user has toolbars and side panels open, there's a strong likelyhood of them showing up in the new window, which will mangle your layout. Again, you'll need to test this in every browser, and even then you can't be sure without knowing all the config options that might affect it.
Opening a new window does not give you a modal dialog box. You can't prevent the user from clicking back to the parent window and ignoring the dialog box.
Therefore, if you want to make a dialog box, you would be much better off using a javascript library that opens a box inside the current page. It's much more flexible, and gives you much more control over the end result than window.open().
If you're using JQuery, you might want to start by looking here: http://choosedaily.com/1178/15-jquery-popup-modal-dialog-plugins-tutorials/, but there are stacks of others available (it's a very easy thing to write, especially in JQuery, so there's plenty of plugins out there you can try till you find one which is perfect for you)
Try changing it to window.location.href= 'url + target="_blank"'
We have written a small javascript function which checks if a URL should open in same window or a popup. In cases when a url should open in a new window IE is giving some strange behaviour a window popup flashes and closes with a beep sound. Can anybody suggest whats going behind the scenes i do not think its my javascript which is wrong. Is it some browser weird behaviour.
I suspect you have a third party pop-up blocker installed.
Yep, this sounds like some third party stuff. By default IE will try to guess what it should do with popups (open in a popup window, open in a new tab, don't open at all) but it won't try to open a window and close it immediately (unless caused by some addons or code included in the page). JavaScript errors shouldn't cause the window to close either (unless they really call window.close()).