Close Parent window in fireFox - javascript

Is it possible to close parent window in Firefox 2.0 using JavaScript. I have a parent page which opens another window, i need to close the parent window after say 10 seconds.
I have tried Firefox tweaks "dom.allow_scripts_to_close_windows", tried delay but nothing seems to work.
Any help will be really appreciated.
Thanks

Using only the opener object may not always close the parent window, for security reasons.
What you can do is:
On parent, have a function named closeWindowFromChild():
function closeWindowFromChild()
{
this.window.close();
}
On child, when you want to close the window:
function closeParentWindow()
{
opener.closeWindowFromChild();
}
And this should work fine. :-D

Scissored from quirksmode (EDIT: added a bit of context, as suggested by Diodeus):
Theoretically
opener.close()
should be the code from the popup: close the window that has opened this popup.
However, in some browsers it is not allowed to automatically close windows that have not been opened by JavaScript. The line above works fine in Explorer on Mac, Mozilla, Opera and OmniWeb, but not in Explorer on Windows, Netscape 4 and lower and iCab. In these browsers the user is asked to confirm the closing of the window. As to Safari, it does absolutely nothing.
Rather to my surprise it's very easy to get around this confirm box in Explorer 5.5 and 6 on Windows. Explorer merely looks if the page has an opener. If it doesn't the window has been opened by the user and may not be closed without a confirm. So what we need to do is trick Explorer into thinking the opening page has an opener:
opener.opener = top; // or whatever, as long as opener.opener has a value;
opener.close()
This trick doesn't work in Netscape 4 and lower and iCab, these browsers have more sophisticated ways to determine whether a window has been opened by JavaScript.

Generally, you can't close a window which you didn't open yourself using javascript.

Related

force window open in internet explorer

I guess what I want to do is not possible.
I would like open a new window using javascript, this is easy:
popup = window.open('www.google.es', 'titlebar=no,toolbar=no,location=no,status=no,menubar=no,resizable=no, top=0, left=0, type=fullWindow,fullscreen,scrollbars=yes');
but I want this new window opens in Internet Explorer whatever the parent was. So, I'm navigating in crhome, and opens the new window in IE.
Is it possible?
You can do it the other way around, that is force to open a link in Edge from an IE page,
window.open("microsoft-edge:http://www.google.com");
but it seems that it's not possible to use a similar command to force a link to open in IE.
It can be achieved using javascript and ActiveX (if enabled) but I can't use this in an enterprise environment (too risky)

How to close the current tab of Internet explorer in vbscript or javascript

I want to close the current tab of Internet explorer on click of 'Log Out' button. It is a new functionality to be implemented in my web application. My application supports only Internet Explorer. The page on which Logout button is located is combination of many pages of window.close() is not working.
I have used following code in vbscript to close the current window of browser for Internet Explorer:
if(window.opener = Empty) then
dim x
x = "<%=Request.Browser.MajorVersion%>"
if(x="6") then
window.parent.opener = "x"
window.parent.close
else
'I need code for closing the tab here for IE7
end if
end if
I have used "<%=Request.Browser.MajorVersion%>" to fetch the version of Internet explorer. Itf it is IE6 then code works fine because there is no tab functionality in IE6 but how to close the current tab for IE7. Please help me out in this context so that I may close the current tab for IE7 also. Thnaks in advance!
You can try this to close the tab in IE7:-
window.parent.opener = "x"
window.parent.close
I have faced the same issue and found that this was working fine for me. Although this would give you an extra message(Microsoft warning message):-
Modern day browsers will not allow you to close a window or tab that you have not created with window.open. Any ways of doing it to make it work is a HACK and is bound to break when browsers are upgraded.

window.opener.document.getElementById(..) does not work in IE

Im trying to open new window from parent window when user choose to print the parent window ,i re-draw the parent page in the new page by using :
document.getElementById('demo_tab_info').innerHTML=window.opener.document.getElementById('demo_tab_info').innerHTML;
and then i control the element by javascript(hide some and show some of them).
That work fine with Firefox and Chrome ,but it is not with IE,does there an explanation for this?
also
window.print();
Does not work with Chrome? Can any one help with these two problems?
As for second question.
Function:
window.print()
is supported in all major browser (source: http://www.w3schools.com/jsref/met_win_print.asp)
But it is true that it is not standardized function by W3C (https://developer.mozilla.org/en/DOM:window.print).

Closing Firefox browser by javascript

I'm using simple close browser javascript statement window.close(); but it doesn't work with any browser except IE.
Any help to close browser firefox or opera or chrome.
thanks
you can't close a window with javascript that you didn't open by javascript. Browsers correctly interpret this as behavior their users probably don't want. And the user is the browser's customer, not you, so what they want is what the browser will do.
Javascript can only close a window that it opened, so unless you pop up a new window with js, you aren't going to be able to close it. Which is obviously a good thing.

window.showModalDialog vs. window.open

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).

Categories

Resources