I am currently using Mozilla Firefox 30.0 and it seems that it doesn't support window.close() anymore.
You may refer on the image below or if it is too small for you, here is the
link.
I opened the website of Google using window.open and then I tried to close it using window.close() but it says undefined.
Is there any other option that I can using to close the window using javascript on firefox?
The Firebug console unfortunately does not display the warning that goes along with it, which reads (in the regular Firefox Web Console}:
Scripts may not close windows that were not opened by script.
Also MDN window.close states:
This method is only allowed to be called for windows that were opened by a script using the window.open method.
So, you aren't allowed to call window.close() on windows that were explicitly opened by the user.
PS: This isn't new behavior, but around for ages (even before Firefox was called Firefox).
PS: To give an example, you are allowed to do something like this, only, i.e. close a window returned from window.open:
var w = window.open("http://google.com");
setTimeout(function() { w.close(); }, 1000);
Related
Each time I try to use window.close(); I just get the error Scripts may only close the windows that were opened by them, is there any way to bypass this?
Looks like it’s not.
See the documentation:
This method can only be called on windows that were opened by a script using the Window.open() method. If the window was not opened by a script, an error similar to this one appears in the console: Scripts may not close windows that were not opened by script.
See also window.close and self.close do not close the window in Chrome.
So, I have my chrome extension, runs in background fine. And every few hours it uses the notification API to ask the user a question.
If they click one answer we open a tab in the current window.
Problem: If there are no chrome windows open (i.e. the extension is running as part of "Let google chrome run in the background" option), the tab doesn't open.
Here's the code which works fine as long as there is at least a single chrome window open:
// tried this too: chrome.windows.create();
chrome.tabs.create({url: pathToGo});
How to make "chrome.windows.create()" actually make a window if there are none already open.
Use chrome.windows.getAll(object getInfo, function callback) APIs to get all open windows.
If in the callback, the array of windows is empty, create a new window using chrome.windows.create(object createData, function callback).
Use chrome.notifications API if you are unable to create new window.
http://developer.chrome.com/extensions/notifications.html
I need a function about ShowModalDialog with setTimeout,so I test about popup window
and ModalDialog in Google Chrome and I get some problems.
there are two popup window showing on page load.one is opened by winodw.open(),
another is opened by window.showmodaldialog() like this:
setTimeout(function(){window.open("PopupWindow.html","_blank","")},100);
setTimeout(function(){window.showModalDialog("ModalDialog.html","","")},100)};
After two popup window were opened, I click an button on PupupWindow.html. It will call
the function as follow:
function test()
{
setTimeout(function(){alert("test");},1000);
}
It's work fine in Google Chrome 14. After I update the Google Chrome to version 19,
the PopupWindow.html will be hang when call test() until the ModalDialog.html was closed.
Please tell me why the case broken on Google Chrome 19 or any way to do showModalDialog
and window.open() on Google Chrome 19. Thanks for help.
The new version of Chrome is actually exhibiting correct behavior. The same behavior occurs for me in Safari as well as Firefox.
Modal dialogs by their very nature are supposed to prevent the user from interacting with the rest of the application until they complete the modal dialog.
Chrome has been plagued by a number of issues with not handling this correctly. See http://code.google.com/p/chromium/issues/detail?id=4202, http://code.google.com/p/chromium/issues/detail?id=16045, and http://code.google.com/p/chromium/issues/detail?id=42939 for some examples. It appears that maybe they're finally starting to clean some of these up if you're experiencing different behavior.
In general using window.showModalDialog should be avoided for a number of reasons that I detail here - http://tjvantoll.com/2012/05/02/showmodaldialog-what-it-is-and-why-you-should-never-use-it/.
If you need a modal dialog I highly recommend jQuery UI's dialog plugin.
Running Firefox 12.0. I'm just starting to write a app that I want to run on localhost. I want it to open it in a (600,400) window, but since I have Firefox set to open everything in tabs I thought I could bookmark it and right-click to open it in a new window.
$(document).ready(function() {
window.resizeTo(600,400);
});
Doesn't work. Is what I am trying to do possible?
Thanks, Jim
This isn't possible, unless the window was opened through javascript using window.open and has only 1 tab in it.
Since Firefox 7, it's no longer possible for a web site to change the default size of a window in a browser, according to the following rules:
- You can't resize a window or tab that wasn’t created by window.open.
- You can't resize a window or tab when it’s in a window with more than one tab.
MDN docs
I have the following JavaScript code to pop up a window in Internet Explorer. The code is executed from a page within a Microsoft CRM modal dialog box. (RequestID is a string that is always the same in the test system - at the moment it contains "abcdefg" - without the quotes).
var cancelUrl = "CancelRequest.aspx?RequestID=" + RequestID;
alert("About to open a window.\n\n" + cancelUrl);
window.open(cancelUrl);
alert("Window opened");
I expect to see a message telling me that I am about to open a window. I then expect to see a window open and get another message about the window having been opened. I don't really care about the order of the last two events; the alerts are there so I know the code has been executed.
I have two PCs and a virtual PC. All running IE7. On the Windows 2003 VPC, the messages and pop-up appear every time without fail.
On the Vista PC and WinXP PC, the messages appear but the pop-up only appears intermittently. (I think this may be the case on the Vista PC too).
All three have identical settings in IE. All have the IE pop-up blocker disabled and have no other pop-up blockers installed.
Can anyone shed any light on this?
Ah, I think I got it... missed it in the description...
You are trying to open a non-modal window from a modal dialog in IE.
This AFAIK, should not work.
Try opening another modal window instead.
Effectively you are saying...
on window A, open up modal window B, now open up non-modal window C, which isn't really valid.
This code is simple. Use debugger and see what is going on.
Check that site with FireFox or Chrome, they have JS debuggers.
Edit:
Add try/catch block around window.open() and see if there is some exception there.
Edit 2:
I see now that you are sending characters as RequestId. You should check if that URL can handle that kind of value. Since name is RequestId I'd say that there is big chance that there should be numeric only parameter. If that is correct, then it can happen that server side crashes when you try to open window and then nothing happens. Reason more to set try/catch block and test.
You might want to try Firebug lite, which will work for IE.
http://getfirebug.com/lite.html
The try/catch other people have mentioned is also a good idea. I think.
Additionally, is there any chance that the pop-up is trying to use a window that is already open but minimized. So it doesn't appear to be working but it's really just reloading the minimized window?