Chrome: window.print() print dialogue opens only after page reload (javascript) - javascript

I am facing a really weird problem. I am calling window.print() from a javascript file. This is working fine in Safari, IE, Firefox... and until two hours ago it worked in Chrome, too. (Version 29.0.1547.57)
I did not change anything essential in my javascript file (really - I just removed some comments...), but what now happens is really weird: In Chrome, the print dialogue does not open when window.print() is called. Nothing happens. But then, when I press reload, the print dialogue opens immediately.
The behaviour in the other browser did not change. And while debugging in Chrome I can see that window.print() is called as expected and the script goes on after that. Only the print dialogue is not shown until pressing reload.
Has anybody ever experienced something like that? I also tried to call window.print() in setTimeout(), but this did not change anything. When I debug the content of the page which shall be printed appears to be perfectly loaded.
I am sorry to ask, but I did not find anything while researching. Any help would be appreciated!
Thank you!

Wasiim is right, there is a Chrome bug where window.print() does not work when there is a <video> tag in the DOM. I solved it by calling this function:
function printPage() {
window.print();
//workaround for Chrome bug - https://code.google.com/p/chromium/issues/detail?id=141633
if (window.stop) {
location.reload(); //triggering unload (e.g. reloading the page) makes the print dialog appear
window.stop(); //immediately stop reloading
}
return false;
}

From my experience this is due to continued background traffic, e.g. ajax calls and the like that prevent Chrome from feeling the that page is loaded completely. The reload breaks all traffic and thus the print dialog pops up.
This is a particular gotcha in Visual Studio 2013 where BrowserLink continually ticks away in the background.
This can be tested by disabling BrowserLink via the setting below:
<configuration>
<appSettings>
<add key="vs:EnableBrowserLink" value="false"/>
</appSettings>
</configuration>

I have exactly same problem with Chrome. You need to manually reload page:
Print

If by any chance someone is using VS2013 with chrome, this problem is caused by the BrowserLink funcionality.
see SO answer here

Similar behavior in Safari. It is caused by opened HTTP request(s) on background.
When any HTTP request is in progress, window.print() is executed successfully, but no dialog is opened!
You will have this issue, when you use a long polling (for server push). Because client will have already opened HTTP connection for a long time, window.print() will never work.

I am most certain you are experiencing this issue because you have a video element on your page - most probably an MP4.
If you disable this video / or have an OGV video instead, the printing should work fine.
It is a bug in chrome itself due to limitations of Chrome's video implementation. It is also important to note that if the user prints manually with ctrl-p / cmd-p, print functions correctly
http://code.google.com/p/chromium/issues/detail?id=141633
Hope this helps :)

Related

Chrome JavaScript turned off

Okay, here's my problem. I wrote some JavaScript for a page, for some reason the page doesn't work in Chrome. The site does what I expect in Opera, Chromium and Firefox. In the Choom devtools there is a kind of error showing in the source tab showing "JavScript is disabled" in a mouse hover popup:
I turned off all chrome's extensions, Javascript in on in the content settings and I cleared all JavaScript exceptions I had, but this didn't seem to change anything. The weird thing (an other one) is that some other sites give the same alert icon in the devtools (including this one) but JavaScript works just fine.
If you perform the exact same functions in the console then, some of, the functions perform just fine.
Does anyone have an idea what I could be because I am out of idea's and it is really annoying that I have to switch browser to test the page (page is 'live' here). Thanks
Have you checked the DevTools settings? You might have accidentally enabled "Disable Javascript"

Firefox page load event very long

I'm going to try to explain an issue that scratch my head...
When I open this website for the first time after opening Firefox (v43.0.3), the UI freeze during about 20 seconds and I don't undersand why. For example you can see that the background image appear after almost 20 seconds...
So, I used firebug net panel to try to understand where the problem comes from and I notice that the page load event is very long but I can't see any tasks executing during this event.
here is a screenshot of firebug Net Panel
When I open the website with Chrome it works fine, does someone has ever encounter that kind of problem ?
I hope that makes sense, thank you in advance.
You're making 31 requests (according to my NET panel - FireBug) which add to 323ms (at least in my case). Your background image is loading ~1s after. Maybe if you'd try to reorganize all that sprites you're requesting into less files - but it seems fair as loading time for me.
I once had a problem with Firebug itself. I had to turn it off and\or uninstall to get the page load normally on Firefox.
In my case it was an effect of problem between Firebug and Telerik Kendo JS Library.
Maybe you have a problem similar issue.
Thanks for your answers, indeed it seem's to comes from my firefox configuration or addons/plugins.
I use a Firefox pre-configured by my socity, so I installed a portable firefox to try if it works and the website is loading normaly.
Now I just have to find from whitch config or addons/plugins the problem comes from, thanks again !

Window.print() error in IE in res://ieframe.dll/preview.js

Onclick of a anchor tag i am giving window.print(); call and I get the print pop-up. But on the click of print I get the following script error.
An error occurred in the script on this page.
Line: 2115
Char: 1
Error: Your file waiting to be printed was deleted.
Code: 0
URL : res://ieframe.dll/preview.js
Do you want to continue with the script on the page(yes/no buttons)
May what ever you click Yes/No I don't get the print or in IE8 i get a blank print.
Firefox prints fine. But, fails in IE9.
Can some one help me on this one??
You can also get this error in IE10 if you are calling window.close() immediately after window.print(), especially if your DOM is large. My guess is that the page has not finished rendering when IE10 executes the window.print() call.
You can therefore get around this issue by:
Calling window.close() within a hover event on the page. A print dialgue will steal the user's focus, so the hover event wont fire until the user has finished dealing with the dialogue. We found this to be the best solution.
Not calling window.close() at all for IE10 clients
As window.print() does not have a callback, calling window.close() after an arbitrary delay. I wouldn't recommend this as it will be unreliable
Go "nuclear" with this answer, which loads the html into a hidden iFrame before printing, sidestepping the need to call window.close()
Follow this two Microsoft help articles:
http://support.microsoft.com/kb/973479
http://support.microsoft.com/kb/2652062
At least it seems to be a problem with print driver and or problems with add ons installed in the IE. An other solution is to be uninstall IE 9 and reinstall it.
I ended up replacing/upgrading the printer driver on the server end, removing the printer on the desktop client and recreating the printer via the handy UNC path (double \ which doesn't show here) \server\printer" add method.

Javascript file loading twice

I am having a strange problem in Google Chrome. I am including a js file via script src tag. I place alert('test') in the file and when I load the page in Chrome, It alerts twice. In every other browser it alerts once. Is there any known cause for this?
Here is the code that loads the JS:
<script type="text/javascript" src="/js/main.js"></script>
It appears this happens in Safari as well. Does not occur in IE and firefox.
I had this recently and eventually found out it was a chrome extension, specifically the cache killer extension
This might be helpful
Webkit browsers (Chrome, Safari) are loading pages redirected from .htaccess twice!
I've noticed this same problem in Chrome. I have some code that runs when the page loads and I have an alert inside that code. In every browser other than Chrome this code is run once, thus the alert displays once. In chrome the alert shows twice. I am not doing anything special, just running code when the onload event is triggered within <body onload="somefunction()">. I am not using links, iframes, or the Cache Killer extension. I tested it in Safari and the code is only being called once. This seems to be a Chrome specific problem.
I did some research and it appears this is a bug with Chrome. I found this link https://code.google.com/p/chromium/issues/detail?id=64810
Depending on your specific situation, this page may give you a work around for the problem.
The problem does not seem to be fixed as of yet.

Firefox and IE continue to load after content has been inserted into a DIV

I have a situation where I'm inserting javascript generated HTML code into a DIV. One would think this would be a no brainer, but for some reason, once the code is in, the status bar and tab loading graphics start up in both browsers and never stop again. The page continually appears to be loading data, but in reality, there's nothing more to load. Any idea why this may be happening? Solutions? I appreciate any help. Thanks!
Install the Firebug plug-in for Firefox. Open it up and got to the NET tab. That will allow you to see your network activity. Something on the server may be stalling. This will help you find it.

Categories