Disable print preview in Chrome - javascript

Is there a way to disable the print preview in Chrome using javascript? I need to open a pop-up in a web application with some text to print; in this pop-up I have the following code when the page is loaded:
$(document).ready(function () {
window.print();
});
a simple JavaScript that opens the print preview page; now, what happens is that the print preview page behaves like a modal dialog: I cannot navigate anymore in the application that has opened the print page (even though the links are clickable). This behavior doesn't show up if the normal system dialog is available (and in fact, I don't have this problem in IE Explorer and in Firefox).
So, is there a way to tell Chrome to disable the print preview through a JavaScript?

Is there a way to disable the print preview in Chrome using javascript?
No (through javascript). Google like every other company, likes to keep a consistent user experience. If programmers were able to change how chrome worked on different pages beyond html, that would be a poor user experience.
now, what happens is that the print preview page behaves like a modal dialog: I cannot navigate anymore in the application that has opened the print page (even though the links are clickable).
Instead, you could have a new window open with the same data and hava javascript do a print. The previous window would work normally (assuming the new window doesn't open in a new tab because of add-ons/configuration).

Related

Show PDF for Website Printing

Can you link printing a webpage to printing a PDF?
Ideally, the PDF would be downloaded once the user uses the browser's print functionality (so a performance hit doesn't affect users who are not printing the website).
I'm looking for a Javascript/CSS print media query solution.
To answer my own question:
You can trigger Javascript to run on a print event, redirecting the user to a PDF (works for IE 5+, Firefox 6+, Chrome 9+, and Safari 5+):
Detecting browser print event
Replace the console.logs in the code snippet from the above link with window.location = "http://whatever.you.want.com"
Using this method, the print dialog will open briefly, close immediately and redirect the user to a PDF where they will have to hit the print button again.

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.

Stop Mozilla Firefox opening popups in a new tab

I am building a site which when you click a link it opens up two things; it opens up a pop-up and an external website in a new tab. This is so the user can interact with the pop-up whilst he/she browses the external webpage.
This was working fine for me but I think when my FF updated to version 15.0.1 on OSX lion, I can no longer get this to behave the way I want it to.
I have even changed the settings in FF: FF->Preferences->Tabs->Open new window in Tab instead to off and with no such luck.
I have also noticed that facebook connect on any site will open a new tab rather than a new pop-up too.
I can't seem to find any documentation on the web stating that this is FF's native behavior, even in their changelog.
Here is my javascript trigger which I am certain all the parameters are correct:
popWin = window.open('http://somesite.com','myTargetWindowName','height=650,width=450,pageXOffset=900,pageYOffset=900,scrollbars=yes');

Use System Print Dialog in Chrome in JavaScript

We have an issue where Chrome's "Print Preview" does not print our pages correctly. If you use the "Use System Print Dialog link" (Ctrl+Shift+P), it prints our page fine (almost identically to Firefox).
We have a button on our page that calls window.print() to open the print dialog. However, in Chrome it opens to the "Print Preview" dialog which ends up not printing our page correctly.
Is there away with JavaScript to print directly to the "system print dialog" in Chrome?
P.S.
I do know how the end user can disable the Print Preview in chrome://flags, but what I want to know is there anyway to prevent it from showing when I programmatically call window.print() (or similar) regardless of user settings.
Print dialogs are not scriptable using JavaScript. They're proprietary parts of browsers themselves.
Hi i am facing the same issue... I even tried firing keyboard event ctrl+shift+P from my script in order to show system print dialog.
You can fire a keyboard event and that issue is successfully dispatched, however the value of keyCode that the browser receives is always 0 (instead of ASCII value of ‘P’)
There is a bug logged https://bugs.webkit.org/show_bug.cgi?id=16735 against webkit for the same… and here are some posts http://code.google.com/p/chromium/issues/detail?id=27048, http://code.google.com/p/chromium/issues/detail?id=52408 mentioning the same issue in Safari and Chrome…

What is the difference between Popup , chromeless window, modal-window, lightbox, hover ad?

What is the difference between Popup , chromeless window, modal-window, lightbox, hover ad?
Which is unblockable with default setting on any browser, more accessible with screen reader and even accessible if javascript disabled?
Popup: Anything that pops up from your browser. They tend to annoy users, and therefore they are often blocked by the browsers.
Chromeless Window: Just another kind of popup window that doesn't show the browser menu or toolbar.
Modal Window: The JavaScript alert() method is an example of a modal dialog. The users must acknowledge the popup before they can return to operate the parent application.
Lightbox: A modal-dialog JavaScript implementation normally used to display images. Requires JavaScipt and it isn't blocked by browsers unless JavaScript has been disabled.
Hover Ad: These are implemented in JavaScript similarly to Lightbox, but are not modal so the users may continue using the parent application. They are used for online advertising solutions and most implementations do not scroll with the web page, and therefore may obscure some of the content. While there is a big chance that Hover Ads may annoy users, they are quite difficult to block.
Depending on the Browser you use, Internet Explorer and Firefox completely blocks the pop-ups with JavaScript Disabled, Google Chrome on the other hand lets Alert Boxes and Announcement boxes still pop-up.You can test it here using your Google Chrome Browser: Alert Box

Categories