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.
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 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.
I'm trying to find a way to take a link from one browser and open it in another browser. This could be taking a link from a Firefox tab and opening it in Chrome, or taking a link in a Chrome Incognito window and opening it in a non-incognito Chrome window.
Here's some more detail. I have a webpage that refreshes every second, and uses javascript(via Greasemonkey/Tampermonkey) to search for certain keywords. When a keyword in my list matches one associated with a link on the page, it automatically opens that link in a new tab. If it's possible, I need to take those links to a different browser somehow, automatically.
AFAIK, something like this isn't possible with javascript due to security issues. The only two solutions I can think of are:
1: Using AutoHotKey to make a macro to copy the link, alt-tab, and paste into the other program. This is manual, I want something automatic. EDIT: I realized I can use AHK to monitor a page, but I don't know if it could be done without introducing more latency than I would like. Keeping the total time from the webpage refreshing to opening the link as low as possible is the most important thing.
2: Having some other program handle it for me. I'm not aware of any and wonder how difficult/costly it would be to roll my own or have someone make one. I'm not even sure if I could interface it with my current script.
I'm fairly certain it would be possible with number 2, although I don't know about cost or difficulty... could there be another way to accomplish this?
For reference, this is the relevant section of code that I'm currently working with. It opens any link which matches a list of keywords in a new tab. These are the links I'm trying to figure out a way to open in a different browser. It uses dynamic object names and a dynamic URL, but essentially this is just saying if the checkboxes are checked and a link matches my autoOpenList(keyword list), then open the link in a new tab.
if(jQuery.inArray(autoOpenTemp,autoOpenList) != -1 && window['autoAccept' + autoOpenTemp].checked && autoAccept_input.checked ){
var tempURL = LINK_BASE+obj.acc_link;
window.open(tempURL, '_blank');
}
Use Java's HttpServlet Class to create a web application. You can setup the server by Tomcat. Servlets Quick Guide.
Start CLI by Java and open browser through CLI.
Call the web application by url on your page.
ASP.Net Webforms pages are wrapped in a massive form, which restricts other forms on the page because nested forms don't work. This is intentional because in a webforms project, there can only be one form per page, and all of the server/client interaction require it. In order to build a custom form, I put together a modal dialog in this way. In order to allow for proper error messages from the server, my modal dialog has to post back to itself. In order to do this, I followed this trick to use the form target as the name of the window the dialog is in.
The problem comes when I try to add a button to download a file. When I try to download a file from this dialog now, nothing happens. I can redirect my response to the file in question, but I can't write the file to the response because the dialog box just sits there when I click the button and nothing happens.
After quite some time researching and building a small test case, I found out that there are several interesting factors here.
Response.WriteFile() works fine in webforms, even when the form is set with a target of the current window.
Modal dialogs can download files perfectly fine, unless the form is set to the target of the current window.
Through extensive testing, this appears to be an obscure bug, or perhaps even a strange attempt at security. This also appears to be specific to IE 8, though I didn't get to test other versions of IE.
The trick to allowing the download inside the modal dialog is to change the form's target.
function downloader() {
document.getElementById("form1").target = "_blank";
}
This fixes the IE bug and appears to work in all other browsers (though I couldn't get opera to show the pop up at all, even with "allow all popups").
Thought my day of toiling shouldn't go to waste and maybe this will help someone else in the future.
Using JavaScript, is it possible to add a bookmark in Firefox directly, without opening any dialog box? That is, I want the user clic on a link and that the bookmark is automatically created, without the need to any further step.
Fortunately, no. It would be a horrible breach of security.
Could be a different story in the context of a Firefox Extension, but I assume you are asking for a normal web page.
If it was possible, any possible website would be able to create any kind bookmark, without the user even noticing.
As a user, I certainly hope this is not possible ^^
(And, as a developper, I don't think it is)