Show PDF for Website Printing - javascript

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.

Related

Disable print preview in Chrome

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

javascript : window.open

I am working in vb.net 2005. I am in a position to start a new browser with process.start().
Now I have to open that browser in a specific size(say height:300 width:500)
Process.Start("firefox.exe", "abc.html")
and I have written this following code on load of abc.html
var myRef = window.open('abc.html','','left=20,top=20,width=300,height=500');
but it does not resize.
If I add 1 button on this page and click on it (by writing same code on its click event), a new window with expected size opens.
Am I going wrong somewhere?
Thanx.
Firefox doesn't let pages resize the window by default. Also note, if you already have Firefox running then browser preferences will dictate whether you get a new window or a tab. You can force a separate instance of Firefox by using the -no-remote command line flag, but then you won't be able to use the default profile (only one Firefox instance per profile).
My questions for you are:
Why are you launching Firefox from another executable at all instead of just having users click on a link and have it open in their default browser?
If you do need to launch Firefox from an executable, why spend all this effort overriding the user's preferences and settings?
If you' re launching from an executable and are keen to annoy your users whatever the cost, why not just find and resize the Firefox window using the normal Windows APIs?

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…

.click not working in chrome

A sample of my code is here: http://develop.davzy.com/test2.php
<input name="avatarfile" type="file" id='uploadbutton' />
<script>document.getElementById("uploadbutton").click()</script>
It is supposed to open the file selector as soon as you open the page. It works in IE8, IE9, FireFox, but not in Chrome.
It won't work, not even in Firefox (7+). It's a security measure to avoid hijacking of the input field.
Regarding the pop up, Firefox warns you that the page is trying to pop up a window (the file upload dialog is an ui window) on page load, so the user is notified and is given the choice to allow it or block it.
Anyway, why would you need to open an file dialog on page load?
is because the browser blocks pop-ups, at least in firefox tells me a pop-up blocking

Android browser run javascript window.close()?

Is it possible to close an Android browser window with window.close() or something related? I can't get anything to work on Android (on desktop browsers Chrome and Firefox I can window.close() without problems).
Thanks
Unfortunately, No.
I have a situation where I launch the zxing scanner app from my browser. It returns in a new browser window. I snag the data but then need to close that tab. And have yet to find a solution to get that tab closed, either through a user clicking a button on the page or in the body load. So it seems you can only put instructions on the page to have the user close the tab.

Categories