Server webpage window - open + print + close - javascript

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)

Related

Dismiss an Alert shown by another application

I have a question that may seem slightly vague, but I am not sure how to go about solving it.
Our office runs a headless machine that is a print server, connect via third party software. The issue that I am having, is that if for whatever reason, the system becomes disconnected from the host server, by means of connection issues on either our end, or theirs, an Alert dialog appears, and the printing will be halted until the dialog is dismissed.
The application is run through Internet Explorer, and appears with with the following dialog.
I originally tries using Java, and a Robot to blindly click the okay button, however the issue is that the dialog will appear in different places each time, and sometimes the message will appear multiple times if not dismissed immediately, so blindly clicking a screen coordinate will not work.
My next thought was to search for a PID, and kill each message by name, or PID, however because it is an Internet Explorer application, that is not a possibility.
Any thoughts as to how I could blindly dismiss these messages, either automatically, or through an external signal?
Edit
I have determined that the dialog is created using JavaScript, and I now have an alteration to the question, how can I dismiss this alert() call? I have read that using JavaScript, you can not dismiss the message, but would there be a way to inject a custom script, to overrride the call to alert?
i.e., a dead function that overrides the system alert?
function alert(){
// do nothing
}
How could I append this to the already loaded page...?
I suppose you don't have access to the source code of the print server app so the best way for you to do is add a bookmarklet which contains a javascript code overriding the alert.
A bookmarklet basically is a piece of code stored as a bookmark in a web browser
To create a bookmarklet, open up Notepad and create an HTML page with this content:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a id="codeOut" href="javascript:(function(){ window.alert = function(){};})();">Your Bookmarklet</a>
</body>
</html>
Save the file as "Bookmarklet.html"
Open the file with Internet Explorer
Right-click on the "Your Bookmarklet" hyperlink, select "Add to favorites" and give it a name
Once your application is loaded and your bookmarklet added, in IE select Favorites->"Name of your bookmarklet"

How to Printing Without Print Preview Window

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.

Will Firefox start my SDK extension automatically after the browser starts - loading screen

I am new on add-on development using the SDK.
I want to ask you guys if it is possible to start my extension automatically after I open my browser? At the moment I starts after I press my widget icon in the toolbar (the panel shows a table with some data I get from the DOM).
Another thing I want to ask you: is it possible to show a loading screen (like a ajax gif) inside my panel (my extension needs a few seconds after switching a tab, to get the DOM data) every time I press the toolbar button.
First of all: One question per post, please.
Extensions are always started with the browser. When it comes to SDK add-ons, your main.js will be called. It's your job to perform any additional initialization form there.
Panels contain regular HTML pages and therefore can use images.
It's impossible to tell you more, without you providing more details and the code you got so far!

Printing a Word document from IE without opening print dialog

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.

Window.open reloading window

I have a an iframe that has a report within it. What I also have, is a feature to allow the user to detach the report within the iframe and open it up in it's own window, using window.open() call.
My problem is, when I press on the detach button, the whole report that initially loaded in the iframe actually goes through the motions of re-running the query again and so presents the user with a white screen until the report eventually renders again.
Is there anyway of not re-running the report in the detached window or somehow grabbing a cached version?
Thanks.
If you already have the HTML on the client side, you can write that to the popup window without going to the server.
var w = window.open();
w.document.write("Text in new Window");
That will open a window and write some text to it. All you need to do now is get the content from your iframe and write it to the new window. Bingo :)
BTW IMO: Opening new windows in browsers should be avoided where possible as many browsers block it and most automated UI testing tools don't support it.
EDIT (in response to comment):
Here is an example of reading from and writing to an iFrame using the jQuery JavaScript library.
// Write to
$("iframe").contents().find("body").html("Test Html")
// Read from
alert($("iframe").contents().find("body").html());
This basically finds iframe elements in the document and reads and write content to them. If your not using a JavaScript library I highly recommend learning up and using one of them.
BTW: My advice on popup windows also holds for iframes. You should avoid using them where possible.

Categories