window.print() triggers Confirm Dialog Preference box - javascript

I have a new window that I open with
window.open()
In the new window I run a javascript function with the onLoad option in the <body> tag of the New window's HTML.
Within the JS associated with new window, I call window.print(). This causes the Confirm Dialog Preference box to open in Firefox 42.0b8.
Is there a way to avoid this behavior(the prompting of the Confirm Dialog Preference) or is it inevitable if I am calling window.print() from a new window?

I ran into this same issue. The fix is to:
Hit Shift+F2 - this opens the developer command line at the bottom of the browser
in the developer command line, type in:
pref set dom.successive_dialog_time_limit 0
and hit enter.
This was a tough one to track down. It's not a programmatic solution, but hope it works out for you.

Related

Why is window.close() suddenly not working?

My application opens new PHP from an icon or link in a new browser tab. For several months now, I've been using a simple JavaScript function to close the current browser tab.
Suddenly, over the past few days, the Close link only works when the Window is first opened. The moment you do something on the page (click a link, press a submit button), it doesn't work. I'm at a loss as to what the problem can be. Nothing has changed in the code.
The HTML href statement is:
<span>Close</span>
And the JavaScript function is:
function windowClose() {
window.open('','_parent','');
window.close();
}
This is happening with both Edge and Chrome on a Windows 10 platform.
Could it be caused by some update to the O/S, Chrome or Edge application?
According to MDN, "scripts can not close windows, they had not opened"
If the tab has been opened by you (you typed the url and hit enter manually), there's no way you can close the window with Javascript. However, if for instance, you started your project with npm start (React in my case), the page can be closed with the code you've provided. Though when you try to re-do it by manually opening the webpage and closing the tab - you will fail.
All in all, don't try to close the window that was not opened by js.
Reference: https://developer.mozilla.org/en-US/docs/Web/API/Window/close#closing_the_current_window

IE10 Blocker Window.Open() Issue

I have a problem only affecting IE and no other browser (what's new?)
I'm using jquery-terminal (http://terminal.jcubic.pl) here where the user can input a command into a prompt and based on their command a window will popup and take them to a specified URL.
Eg: If a user types google into the command prompt it should open a new window and take them to www.google.com
if (command.match(/^\s*google\s*$/i)) {
window.open('http://www.google.com', '_blank', 'location=yes,height=570,width=520,scrollbars=yes,status=yes');
else if ... bing, yahoo, etc.
Okay, so IE will open the window and load the URL the first time without any hiccup if the user types 'google'. The problem arises when the user closes that window and goes to type in 'google' again, the window loads with a blank page instead of going to the URL.
So I ask, is there a way to fix this via code, or is IE trying to protect the user in its own way (ie. Settings problem?).
Thanks in advance.

window.print in new window breaks hashchange in windows chrome

This may be a specific issue with Chrome that I should take to their forums, but I wanted to see if there was an alternate solution or a fix. We are using backbone.js for our single page app and to print, we create a new window, write our html to it and then call print on the new window. If a user closes the tab without closing the print dialog, the hashchange and popstate events do not fire anymore in the Backbone.History object. You can't refresh the page either. We have to close the page and reopen in a new tab to restart.
This error does not occur on linux builds, just windows. If the user closes the print dialog first and then the tab, everything works normally.
The ideal solution would be for the hashchanges to keep working. If this isn't possible, is there another solution to do a print of a certain portion of HTML?
I've tried writing a script that calls window.print() in the new window but it does not fire or even throw an error. IFrames will not work because the css of the single page app will overwrite the printing portions html. Any solutions are welcome.
Here is a jsfiddle to show you the problem.
http://jsfiddle.net/5P4qv/3/
window.document.getElementById('run_print').onclick = function () {
window.onhashchange = function () {
console.log('hashchanged');
};
window.location.hash = 'test';
windowObject = window.open("", "_blank");
windowObject.document.open();
windowObject.document.close();
windowObject.focus();
windowObject.print();
};
You may need to allow popups for this to work. Click the print button and the popup will open to the print dialog. Close the window without closing the print dialog and the original window will act as if it is still loading. You will not be able to refresh either.
Again, this is only on Chrome in windows.

window.open() Opens as popup in chrome, But I need it to be open in another tab instead

I have a timeout function call, inside that I want to trigger a " window.open(redir_URL,"_blank"); " which should open in a new tab, but its opening as a popup.
Also its not user initalted event, its a javascript call.
Ref: http://upshots.org/javascript/window-open-opening-in-popups-vs-new-tabs-with-set
With ref to this, I tried to trigger a click event , but that also opens as a popup.
Any one please help me out this?
Chromium ticket: http://code.google.com/p/chromium/issues/detail?id=20189
This is a browser setting and not something you can control with code. In my browser, your "window.open" will open a new tab, because that's what I have mine set up to do. In others' browsers, it might open a new window.
Reference:How do you open a new tab in chrome using HTML/JS?

Html javascript to open new window and close current window

I have a popup window and in that page I have the following code in the body.
<img src="...something"/>
The purpose is to have this popup window close when a user clicks on the image link, and to open a new page and be directed to http://www.example.com.
It works in IE and Chrome, but not in Firefox. The popup window closes but no new window is opened.
Any ideas?
Yes, I can repro this - interesting. setTimeout works around it:
onClick="javascript: setTimeout(window.close, 10);"
I can only guess that once the window closes (which happens before the hyperlink is followed) Firefox stops processing that page.
Edit: better make it 10ms delay - with 1ms Chrome doesn't close the window.
The question is actually solved for the opener but it didn't help my issue (not wished: the new windows under firefox keep the same size as the current popup).
So I find following solution:
function whenClicked()
{
window.close();
opener.location.href = "http://www.example.com";
}
or this if the ppage should open in a new tab:
function whenClicked()
{
window.close();
opener.open(http://www.example.com, '_blank');
}
When you add some functionality to an element's click event via javascript, that functionality is executed before the default click event (in this case, opening a new page), in order to allow for the possibility of intercepting and overriding the default event. The default behavior will only execute when and if the event returns a boolean value of true.
In this case, the additional functionality would be to close the window and my guess is that Firefox chooses to interpret this as "we're all done here", so the click event never returns true, and thus the new page never gets opened.
Evgeny's suggestion of using a short timeout would allow the click event to return true before the window is closed, thus allowing the new window to open.

Categories