I am calling print function on onclick event with javascript.
<input type="button" value="Print" onclick="window.print()" />
I use this code for printing a page but i want to pass 'print preview' window.
How to print directly to default printer without opening dialog box of print.
VISIT MY PAGE WWW.......
(USER CLICKS)
KOBOM! 100 pages printed.
It should not be possible because it would otherwise be a security issue(this case; spam). Your code involves I/O-communcation and this goes via the browser(everything goes through the browser but here they take control from your code). You are actually doing it right, but the browser you have chosen have decided to popup a dialog box and wait for the user to accept the print command.
Well,the browser designer wants a good user experience for their users and in this way they prevent potential spam. Javascript knows it and thats why there is no parameters for this in the printer function.
You still want to do it? try to find an add-on or a tweak for your current browser to allow such bypasses. Create your own application(could be a browser).
Issue with this approach? You dont want to ask other users to install or configure such things; Too much for the average user and your intent was to make things easier.
Related
In a web-based ERP , we need to print POS reciept on the client . When I click print on client another web page opens up, and I have to click print again so that it goes into the printer. Then I have to close the window and then go back to data entry webpage page again.
How can I print from the client browser most efficiently? i.e. After the data is saved, I click print and it opens, prints and closes the browser window automatically. How can this be achieved? In offline versions it happens, but when i take it on browser it doesn't occur. Pls help
Front end:- .NET, HTML5, Javascript, Jquery
Backend (Database):- MS SQL
There is one way to print a page using JavaScript, excluding additional libraries. It uses a method called window.print()
You seemed to suggest that you wanted to remove the prompt that happens with the window.print() method. I don't recommend this behaviour, as most people don't want their printer suddenly spitting out paper, not to mention that this is technically malware. However, assuming you have a legitimate use case for this behaviour, there is a duplicate question with answers already.
HTML / Javascript One Click Print (no dialogs)
I have a web extension that lets any website access the clipboard. On request I will ask the user if it is okay to give access to the clipboard.
I do this in two ways
I create a notification
The problem: firefox doesn't allow buttons, so in the message I say "Click here to allow website x access". I added an eventlistener to the notification that sends a message back to the content script and it proceeds from there. It's okay but not really the best solution (I want buttons)
As a fallback I have a simple confirm box.
The problem: it doesn't really look good.
Now my other idea is to create a custom confirm box. That means create some html, css and javascript and append it to the DOM. This although is potentionally dangerous as websites can just trigger a "click" on the "allow access"-button then.
So I am basically looking for a nice and safe way to get confirmation from the user.
So what next? iframes? Is it possible to include an html page from the addon with access to a content script in an iframe?
Or is there some other way I can implement this maybe web extensions already offer something like this?
Completely overlooked the click event argument. There is a event.isTrusted property which is false when the event was triggered. (maybe not available in all browsers). But this pretty much solves the issue.
I have a requirement where I need to print a specific word document when I click on a button in IE8/IE9. I tried to find a way using ExecWB and other methods but could not achieve my goal. Couple of constraints I have are as follows.
The word document is availble through URL and this URL is from a different site than the page where I am clicking the button to print (XSS considerations ?)
I need to directly print using default printer without popping up the print dialog.
Is this possible in anyway?
Impossible from within the context of HTML page, without a custom browser extension. Word document must open before it's printed (maybe not visually presented to the user upon opening, but MS Word or some other application that is capable of opening word docs must be installed on the client system. There is Office extension for IE, which can be used to open the document, but the user has to click on the print button to invoke the dialog. There's nothing that you can do from within javascript to accomplish that. I'm sure you could, if you wrote your own IE extension/plugin, but unless your users are corporate that must install it, nobody else will.
I hope I'm not lying to you.
What is causing some browsers to see my code as unsolicited?
I have a web site devoted to helping people with interactive sessions. It starts with the user clicking [Begin] so this is a consented action. This should (1) open a popup while (2) redirecting the first page to a end page as below :
<head>
<SCRIPT language="JavaScript">
function openwindow(){window.open("{INTERACTION}","interaction","resizable=0,width=800,height=600,status=0");}</SCRIPT>
</head>
<body>
<FORM action="end.php" method="{METHOD}" >
<input type="submit" class="button"
onClick="javascript: openwindow()"
value="Begin" />
</FORM>
</body>
As said, this is not trying to open an unrequested popup but some strains of IE and Chrome appear to be treating it as such. I have been trying to get a fix, most recently digesting this post.
In it Bobince comments
these days, you don't really need to ask the question “was my unsolicited popup blocked?”, because the answer is invariably “yes” — all the major browsers have the popup blocker turned on by default. Best approach is only ever to window.open() in response to a direct click, which is almost always allowed.I'm quite happy to buy into this principle because I simply want my popup to open.
What is causing some browsers to see my code as unsolicited?
I'd appreciate any help you could give me. (as you might have guessed, client side is not my bag and this topic has been bugging me for ages).
Many thanks in advance (and fingers crossed)
Giles
No much you can do. You could ask your users to disable pop-up blockers or inform them that a pop-up blocker is enabled by checking the window object ref returned by window.open()
e.g.
var w = window.open('http://domain.com');
if(!w) {
//an alert in this example
alert('oops..seems like a pop-up blocker is enabled. Please disable');
}
you could find another way and try what Brad suggests.
There isn't anything you can do about this. Some popup blockers still block everything, even in response to a user clicking. The best you can do is suggest your users turn off popup blockers, or find a different way to do what you want to do. A popular method is the div that appears on top of all others on your page, like Lightbox.
There are many jQuery plugins which make this easy.
You have (at least?) 2 options to deal with this:
if you want to keep using popups, display a very visible warning for your users, pointing them to instructions on how to configure their browser to whitelist your domain (like the banners that appear on top of StackOverlow.com when you gain new privileges, or even like the banners Chrome is showing for actions - they are web-based as well);
use an iFrame and load its content based on your user's click.
I am a javascript noob, so this question might seem very basic and I might need a lot of directions :)
This is the effect I want to create:
The user is currently viewing a PDF in the browser. The doc is embedded with the tag in the HTML. My PDF has forms in it, so there is some processing (validations etc) that I do inside the PDF as the user is interacting with it. Sometimes, after immediately entering a value the user closes the PDF - and my last bit of processing is incomplete.
In such a case, I would like to (1) stop the PDF from closing till my processing is done (the HTML is aware of the processing status of the PDF, so the HTML knows when a close can be allowed) (2) While I have stopped the PDF from closing, after the user has tried to close the window, I want to display some sort of a message to him indicating that the PDf is not done with the processing yet (3) When the message from (2) is being displayed to the user, interaction with the PDF should be disabled - and ideally this fact should be expressed visually. For ex, the PDF can appear grayed out in the background of the message (4)After I am done with the processing I want to close the browser window
For (1),(4) I am using onbeforeunload, and it serves my purposes well. But on the usability front -(2), (3) - I have no clue as to how I must proceed. It could be sort of what Google Image search does when you click on a thumbnail on the main page. - there is an image in the foreground(I could replace this with a message of my own), the background is grayed. However it doesnt prevent interactions with the background - clicking on it takes me to the original webpage. Also, I dont know whether the JS will work when a PDF is already open.
Thanks!
For the benefit of others, squarehead's answer to his own question is to embed the PDF plugin in an HTML page while making it fill the window.
It'll look the same, but the HTML and any associated javascript will still be around and, if you're dealing with browsers which don't allow content to overlap plugins, you can just use Javascript to reduce the height of the PDF view by a couple of ems whenever a message needs to be displayed in order to make room for a notification bar.
Unless I'm mistaken though, width="100%" height="100%" isn't valid XHTML. The proper solution would be to either use style="width: 100%; height: 100%" or add this to the stylesheet.
#PDFcontent { width: 100%; height: 100%; }
Update: As for preventing the user from closing the PDF before processing is finished, the ability to do so is very restricted in order to minimize the possibility for abuse, so all you can really reliably do is display an "Are you sure?" dialog.
Here's the code I used in one of my projects:
window.onbeforeunload = function() {
if ($('#quote_preview').text() != "" && document.submit_warn) {
return "The currently-entered quote has not been" +
" submitted. Are you sure you want to discard it?";
}
};
I'm using jQuery in this case, but the basic idea is that you assign a function as the onbeforeunload handler which determines whether an "Are you sure?" dialog needs to be displayed and, if so, returns the text to display in it.
The browser controls what extra explanation (if any) will be displayed, what the OK/Cancel buttons will look like, and whether manipulation of the page is blocked while the dialog is open. I don't think it's possible to control that last one yourself.
< object id="PDFcontent" data="untitled1.pdf" type="application/pdf" width="100%" height="100%"/>