Closing Firefox browser by javascript - 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.

Related

How to close current browse's tab?

I am trying to close the current open tab after 1 second.
Here is what I tried :
$(function(e){
setTimeout("window.top.close()", 1000)
)};
The code works in Edge but it does not work in Firefox.
I get this warning into the console when I try to close a page in Firefox :
Scripts may not close windows that were not opened by script.
How can I close the page?
Simply you can not. The fact Microsoft Edge allows you to close tabs is a serious security breach, other safer internet browsers will not let you do something like that.
You can close tabs and windows which were opened by the script itself.
Your code seems correct anyway.

window.close() is working only in IE. How to close current tab in firefox window using javascript?

window.close() is working only in IE.
How to close current tab in Firefox window using javascript?
Pls help me
It's difficult to say wothout seeing your code, but I came to learn that often the cause of such behaviour could be that the window hasn't been opened by javascript so it doesn't allow it to close.
What you can do to go around this is to add a window.open just before your window.close statement; have you already tried that?

Strange Window popup behaviour on IE7

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

Strange behaviour opening pop-up window in Internet Explorer

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?

Close Parent window in fireFox

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.

Categories

Resources