I'm using window.print() from inside an iFrame. This works flawlessly in FF, but not so great in IE7. In IE7, it brings up the Print Dialog, however, the dialog itself is slow, choppy and unstable.
I'm having troubles understanding this problem, and any help would be greatly appreciated.
If I may add, the same thing happens when printing content of the same iFrame from outside of the iFrame in question. Further more, when clicking File->Print the Print Dialog appears to function normally.
Try using:
document.execCommand('print', false, null);
This appears to work in IE7, but you'll probably want to use a conditional and use window.print() for other browsers.
Related
I have a page that contains iframes, i want to print them all using window.print() it works in chrome but not working in IE, it just prints the first page not the rest.
it just prints out the first page not other 5 pages.
any help would be much appreciated!
Not clear with your situation but to help, in IE window.print will always try to print the browser window and not the iframe window you are in unlike chrome and firefox.
To print corresponding iframe window in IE, do something like this.
window.top.document.getElementById("iframe-id").contentWindow.focus();
window.top.document.getElementById("iframe-id").contentWindow.print();
Hope this helps.
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 :)
I have an alert box, and when I run that code in Firefox, no matter what program I have over firefox, firefox appears with the pop-up automatically over other programs open.
This however, does not work in Chrome.
What gives? Would this be a perference change or this there a line of code that says focus on this window.
I used
window.blur();
window.focus();
and that fixed my problem :)
The implementation of alert is browser specific. Unfortunately there is not line of javascript code to change this.
If you want to have customizable (and working the same in every browser) alert window, use jquery UI.
Note: It will be over the actual page, not over the (other) window.
I have a flash menu on a site. The menu works fine in all browsers EXCEPT IE9. It looks like this javascript file is not loading:
<script type="text/javascript" src="scripts/ActiveContentDropDownWide.js"></script>
In IE9 it just displays BUTTON1, BUTTON2 etc but in all other browsers it displays the complete menu. This is what happens when the ActiveContentDropDownWide.js script is removed which is why it seems to be a problem with that script and IE9. But I could be wrong?
Any ideas would be greatly appreciated.
Try doing a Fiddler capture with IE9 and FF. Then, compare the 2 captures using Fiddler's Diff feature.
It is seems to me that the menu is hiding behind the content
maybe it is z-index problem if the flash menu inside a div ,give it high z-index number or google for ie9 z-index problem.
The javascript file that powers some of the menu needed to be updated with a new version that supports IE9. Once I updated it, the menu worked fine in IE9. Thanks.
I have seen many examples on using javascript to resize a browser window, but for me they all fail to perform that function in IE. I include my code to see if anything is wrong with it that I just don't see. The code works great in FF but that is not used at my location.
I am no javaScript expert, but I am no slouch either. If I were new to javaScript I would be hating it. I'm sure it has something to do with IE but I cannot explain it.
Any help would be great.
CODE:
//window.sizeToContent();
window.resizeTo(700, 700);
I read in the docs that sizeToContent will not work in IE but resize should. It is an incredibly simple statement.
This works for me in Internet explorer 8
<html>
<head>
</head>
<body>
<h1>Resized</h1>
<script>
window.resizeTo(400,400);
</script>
</body>
I did some testing in IE9 beta (that's the only version of IE that I have on this machine), and it seems that window.resizeTo does not work on the initial page load. It does work if you refresh the page. Also, it does work if you delay its execution:
setTimeout(function() {
window.resizeTo(200, 200);
}, 2000);
(at least in IE9 beta)
The "working" example with IE is working only because there are no more tabs on the window.
If the windows has other tabs loaded, then it DOES NOT work. It's a security measure of IE8 and higher.
If you need to resize your window, you will need to open a new window. And for that, you will need to make the user click a button with the window.open onclick event, otherwise any popup blocker will block it.
You won't be able to resize the window reliably with JavaScript. It's not possible in IE 7 with tabbed browsing enabled. It's also potentially annoying for the user.
This seems to be IE only.
If your window is a "dialog" like:
window.showModalDialog(url,...)
I found this hacky way to make it the right size:
<script type="text/javascript">
//window.resizeTo(1000, 790); //Will not work if its a dialog
window.dialogWidth = '1000px';
window.dialogHeight = '790px';
</script>