I have an angular js app and for a print functionality I am opening an html page using the window.open method.
public openNewWindow(html: string, title: string) {
var popupWin = window.open('', '_blank', 'scrollbars=no,menubar=no,toolbar=no,location=no,status=no,titlebar=no, height=500, weidth=900');
popupWin.window.focus();
popupWin.document.write(html);
popupWin.document.title = title;
};
I have a button on the html page to Print. I use the onclick event to call print.
<button class="print-btn" onclick="window.print();" id="view_print"> Print</button>
This code perfectly works in Chrome, but not in IE 11. If I change the default from Edge to IE 10 the print seem to be working and opening the print dialog window. It is definitely slower than the Chrome.
I have tried adding the emulation as below (for IE 10 and 8 etc) but it still does not work.
am I missing anything here? I find a lot of articles but I have not been able to fix it.
Scripted popup windows with size and position parameters are subject to Popup blocker and IE Security zone restrictions. try
window.open('', '_blank');
Use the File>Properties menu to determine which IE Security zone a web page/domain maps to.
See any Wikipedia article side bar for a template method of formatting the current web page in a printer friendly format using media queries.
I am seeing this also, but with the following information:
under Chrome: address at bottom of page is (the correct) http://server/path/file.php?querystring
under IE11: address at bottom of page is http://server/path/{8 digit dynamic alphanumeric string}.htm
The onscreen rendering is correct, but the printed result is a 404 error.
The current work around is to use Chrome.
If you have new system, and after trying everything this is not working out,
Try setting Printer First.
Set Default Printer and your IE should start responding to
"Ctrl" + "P"
or
window.print()
Related
I need to print pdf silently in kiosk.
So far I was printing webpage and it worked fine:
//print plugin
<script src="js/jQuery-printPage-plugin/jquery.printPage.js" type="text/javascript"></script>
//definition
$(".btnPrint").printPage({
url: "adres of page to print",
attr: "href",
message:"Please wait."
});
$(".btnPrint").trigger("click"); //I simulate user clicking print button
(Also I added silent print in firefox about:config to hide print dialog. (similar to chrome --kiosk-printing))
The problem is that pdf won't print.
SecurityError: Permission denied to access property "print" on cross-origin object
I don't need to use this plugin, any working plugin will be ok. I have found a lot of stuff all over the internet concerning the problem, but none is work for me - I tried various solutions in chrome/ff
1) creating new window (won't include pdf directly, need to use iframe/embed), printing via object or iframe.
2) On chrome I cant even get pdf printed from iframe at all (I get blank iframe)
3) firefox I can't print iframe contents with pdf inside (whole page that contain pdf will print, but I multiple page pdf will be cropped).
Please have in mind that I'm in total control of the kiosk (windows 7), and I can use any browser, install any additional software.
As usually latelly I answear to myself :P this is how I did it: FPDF+FPDI autoprint (not really answear to a question but working alternative in this problem)
Sorry about the odd title, I'm not sure how to phrase the question. Basically, I was wondering if it is possible open a new window and fill it with HTML from the front-end rather than code an actual route, db calls, etc. (Yep ultra lazy.) Thinking along these lines...
var html = '<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>'
window.open(html);
Am I just wishing upon a star here? Is this even possible?
The first thing you need to do is make the popup have a variable -
var popup = window.open('blankPage.html');
var html = '<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>';
popup.document.write(html);
Edit this answer no longer works because of security features implemented that block certain data: URIs.
See Open a new tab/window and write something to it? for working answer
There is the option to use a dataurl...
window.open('data:text/html,<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>');
Data URIs are currently supported by the following web browsers:
Firefox and all browsers that use the Mozilla Foundation's Gecko rendering engine
Safari, Chrome and other WebKit-based browsers
Opera
Konqueror
Internet Explorer 8+ (with certain limitations)
The suggestion to do the following
window.open('data:text/html,<!DOCTYPE html><body><h1>Y HALO THAR</h1></body>');
no longer works on Chrome due depreciation of the 'data:' allowance.
https://developers.google.com/web/updates/2017/03/chrome-58-deprecations#remove_content-initiated_top_frame_navigations_to_data_urls
If you used this previously, your code will now open a blank window instead.
I am attempting to open an html file in firefox with minimal extras (toolbars, menubars, addressbar, etc). Just the html contents of the webpage, and nothing else. I want to be able to do this within linux from the terminal. I also have to do it in such a way that it works across multiple linux machines running the same version of firefox. So this removes any possibility of using a profile. I was hoping there would be a simple parameter to firefox that would allow me to turn these settings off. I dont believe there is.
The only possibility I have found is through javascript's window.open. It appears the parameter specs to window.open arent even functioning in firefox 1.5.0.9. I have read that some of them were removed in firefox 3.0+, but have not found anything regarding the version I am using, 1.5.0.9.
This is what I am using to open my .html file using windows.open...
test.html:
<html>
<body>
<script>
window.open('./rel_notes.html','_self','toolbar=no,menubar=no')
</script>
</body>
</html>
And then just running 'firefox test.html' from the terminal.
Both the toolbar and menubar still appear when I do this. What am I doing wrong? Is there a easier way to do this?
If your browser settings allow pop-ups without notifications from X source (localhost i presume?) then the following might work:
window.open('./rel_notes.html',null,'menubar=no,toolbar=no');
window.open('','_self',''); //this is needed to prevent IE from asking about closing the window.
setTimeout('self.close();',500);
Taken from a link in the link bungdito gave me:
After a window is opened, JavaScript can't be used to change the features.
So by opening test.html, and then using window.open on _self, I am trying to adjust features to a window that has already been opened, using javascript.
Source: https://developer.mozilla.org/en-US/docs/DOM/window.open
I have written a JavaScript-based print feature for a web page. It extracts HTML from a hidden div on the page, renders it into a new window and triggers the print dialog.
The option is made available over a button with an onclick="printTheThing()" event. I know that for example screen readers have some caveats with JavaScript. I am wondering whether/how many people such as blind or vision-impaired I block from using this feature.
The implementation opens a new browser window and appends to its document:
function printTheThing() {
var dispSettings = "toolbar=yes,location=no,directories=yes,menubar=yes,"
+ "scrollbars=yes,width=550,height=400",
html = $('#theDivToPrint').html(),
printWindow = window.open("", "", dispSettings),
doc = printWindow.document;
doc.open();
try {
doc.write('<html><head>');
doc.write('<title>' + title + '</title>');
doc.write('</head><body>');
doc.write(html);
doc.write('</body></html>');
} finally {
doc.close();
}
printWindow.focus();
printWindow.print();
}
Update: This is what the button looks like:
<button type="button" onclick="printTheThing()">Print the thing!</button>
In addition, I am using CSS to replace the button by an image. I have tested the button with the Firefox plug-in "Fangs". It suggests that screen-readers will perfectly read out the original button text. But Fangs does not provide any interactivity so I cannot test the printing with it.
The Chrome extension shouldn't be relied on at all. You should test stuff with NVDA, which is free. I will guess that Google fanboys will say Chrome Vox is fine. Trust me, I have been working with AT for nearly 15 years.
Anyway, I would need to see the code for the button, not the JS... The JS looks fine. Some people have trouble with knowing there is a new window, however the print dialog should grab focus versus the window
to improve accessibility by using screen readers use W3C WAI-ARIA live regions, for more info see their recommendations and FAQ.
to test you can use the following screen readers:
on Windows - JAWS, NVDA
on Linux - orca (is not working with Chromium) + advice of Florian Margaine
you can also use AChecker to test on compliance of WCAG 2.0, Section 508, Stanca Act accessibility standards.
The best way is surely to try it out yourself.
There is a Google Chrome extension allowing you this: https://chrome.google.com/webstore/detail/kgejglhpjiefppelpmljglcjbhoiplfn
The way to render a printable page is to use #media CSS directives. That way you don't need to do anything special like pop-up another window or worry about accessibility: the content is simply printed correctly (and possibly very differently from the on-screen layout, if that's what you want).
I create a secondary browser window with Javascript code, using the window.open function, and fill it programmatically with some HTML content. It works well for all browsers that my application supports except for one: Safari on Mac. In fact, the window itself is OK but the print command is disabled. Does anybody have an idea why? I should mention that the main reason to show this window is to allow the users to print some data. I guess I could implement a "Print" button in the page but I would prefer not to (and it may not work either, but I haven't tried it).
Here is a simplified example of the code that I use to create the HTML content:
var pp = window.open("", "_blank");
pp.document.writeln("<html>");
pp.document.writeln("<head>");
pp.document.writeln("<title>");
pp.document.writeln("Hello");
pp.document.writeln("</title>");
pp.document.writeln("</head>");
pp.document.writeln("<body>");
pp.document.writeln("The body");
pp.document.writeln("</html>");
pp.document.close();
I tried variations around that code, without any success. My tests are done with Safari 5.1 on Mac OS X 10.6.8. Any help is welcome!
Have the window print itself:
Before your </html> add:
pp.document.writeln("<script type='text/javascript'>window.print()</script>");