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.
Related
So I'm getting a little bug using this simple window.open javascript function on iOS browsers. When I click it I get 2 windows opening. Has anyone run into this problem and does anyone have a work around?
Open page in new window
Thanks!
It's not a bug. You are opening two windows: one because you have an <a> with a target="popup", the other one because you window.open a "name". The only reason it doesn't happen in desktop is because most desktop browsers would exercise their popup-blocker.
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);
The following javascript opens a pop-up in Firefox, Safari, IE, and Google Chrome:
window.open("http://google.com", "foo", "toolbar=yes,location=yes,menubar=yes")
However, in Google Chrome the toolbar (with the usual forward and back buttons, etc.) does not appear on the popped-up window. (Tested on both Windows and Mac.)
How can I fix this? I would like the user to be able to navigate forward and back using the tools with which they are most familiar.
There is a bug open for Chrome:
https://code.google.com/p/chromium/issues/detail?id=82522
It has not received a lot of attention from Google. Vote for it.
Unfortunately Chrome only supports a small set of window features when using window.open. If you believe that this is a bug or an issue you can file it at [http://crbug.com].
If you just use window.open(url) then it will open a new tab in the same window with the buttons you desire.
Updating on current behavior (as of 4/26/2017)
The expected behavior should be a new PopUp Window when size dimensions are passed as arguments to window.open (if toolbar is enabled, then add the toolbar to the PopUp window). If no dimensions are indicated just default to opening a new tab (in this case toolbar enabled is the default).
(Btw, this is FF current Behavior (version 54.0a2)) .
Chrome Behavior (Canary 60.0.3079.0)
Opens PopUp Window to indicated dimensions
window.open("https://google.com","foo","width=800, height=780")
Opens New Tab (browsers default minimized size, ignores size dimensions)
window.open("https://google.com","foo","width=800, height=780,toolbar=1")
FF Behavior
w/Size Dimensions
Opens PopUp Window w/o ToolBar (NO toolbar)
window.open("https://google.com","foo","width=800, height=780")
Opens PopUp with ToolBar
window.open("https://google.com","foo","width=800, height=780, toolbar=1")
w/o dimensions
Opens New Tab
window.open("https://google.com","foo")
window.open("https://google.com","foo", "toolbar=1")
The only option for Chrome is to not specify a third argument. Chrome ignores the third argument as they are rightly allowed to do according to the HTML 5 specification, but if present the window appears to always open in a floating widow without controls.
If you do not specify a third argument the window that opens will be a new tab and will have all of the features the user needs.
If you do specify a third argument you will get a new floating window with no controls other than the URL display.
I know this is an old post, but the most recent answer is from September, 2013, so I am taking that as a reason to follow up with this answer. Advance apologies if this is not proper etiquette.
https://code.google.com/p/chromium/issues/detail?id=82522
That's the link to the bug over on the Chrome support page.
I am posting it here in the hope that others experiencing this problem will raise attention to this issue, as suggested in a previous answer.
My apologies for posting this comment as a separate answer. I don't have enough karma to do this the right way.
What are situation when you want to use window.showModalDialog function? It seams that you can do exactly the same with window.open function and few parameters that remove some of the chrome (navigation, addressbar, etc...)
When would you want to use window.showModalDialog and window.open?
It has been a few years since this question was originally asked and things have changed a bit since then. window.showModalDialog is now officially standardized as part of HTML5 and is supported in IE, Firefox 3+, Chrome (albeit buggy), and Safari 5.1+.
Unfortunately window.showModalDialog is still plagued by a number of issues.
Modal dialogs are blocked as popups by default in Firefox, Chrome, and Safari.
The modal dialogs in Chrome are buggy and aren't truly modal - see http://code.google.com/p/chromium/issues/detail?id=16045 & http://code.google.com/p/chromium/issues/detail?id=42939.
All browsers except Chrome block the user from interacting with the entire window (favorites, browser controls, other tabs, etc...) when a modal dialog is up.
They're a pain to debug because they halt JavaScript execution in the parent window while waiting for the modal dialog to complete.
No mobile browsers support window.showModalDialog.
Therefore it's still not a good idea to use window.showModalDialog. If you need the window opened to be modal (i.e. the user cannot interact with the rest of the page until they deal with the dialog) I would suggest using jQuery UI's dialog plugin.
window.open will work for non modal windows but I would stick with jQuery UI's dialog because opening new windows tends to annoy users.
If you're interested I write about this in more detail on my blog - http://tjvantoll.com/2012/05/02/showmodaldialog-what-it-is-and-why-you-should-never-use-it/.
Modal dialogs are dialogs that once opened by the parent, do not allow you to focus on the parent until the dialog is closed.
One could use a modal dialog for a login form, edit form, etc where you want to have a popup for user interaction but not allow the user to return to the window that opened the popup.
As a side note, I believe only Internet Explorer implementes window.showModalDialog, so that kind of limits your usage of it.
showModalDialog() is currently being standardized as part of HTML5. The third argument (for additional options) is not present in the HTML5 version, and is (safely) ignored by Safari and Chrome.
http://dev.w3.org/html5/spec//user-prompts.html#dialogs-implemented-using-separate-documents
Note that there's a bug in Chrome 2 which prevents showModalDialog() from loading properly. The popup window appears, but the content never loads.
One more reason to avoid using showModalDialog().
showModalDialog()works well in Internet Explorer, Firefox (3 and above)
Works in Chrome but popup is not model (you can go to parent window)
Note that while you can show modal from any popup window, you cannot use window.open from a model dialog in some browsers (IE, Safari).
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?