This question already has answers here:
Landscape printing from HTML
(18 answers)
Closed 8 years ago.
I was trying to set the print orientation into landscape through javascript. I'm only just using the window.print() function for the page's content to be printed.
here's the code:
<a href="" onClick="window.print();return false">
<img src="images/print.png"></a>
With this I was able to print a sample page. But only it was on portrait format. The client requires it to be in landscape. so I tried on many codes I found. here's the one am sure your most familiar with.
<script type="text/javascript">
$("#printLandscape").on('click',function () {
$('head').append('<link href="printLandscape.css" title="printLandscape" rel="stylesheet" />');
});
</script>
since it wasn't a button that am using to call the print function but an image type with href, I tried to change the previous one with:
<a href="" onClick="window.print();return false" id="printLandscape">
<img src="images/print.png"></a>
See the id="printLandscape", I tried that on to be able to call the javascript function declared above and make the page print into my desired format which is landscape. But when I tried to print, to see if it was working. The printed page still has the default/formal or portrait type.
Is there something am missing? Or did I not declare the javascript properly especially the id on href for it not to work fine?
S.O.S
I think you should make the page property landscape in CSS:
#media print{#page {size: landscape}}
The support is left to the browser and it appears not to be supported in all browsers.
Related
I have a wepage that contains a link - to open a new window showing a YouTube video. It works fine in Chrome, but in IE it doesnt work. The IE console says: SCRIPT5009: 'open_win' is undefined (I'm using IE11)
In the head section I have:
function open_win(url)
{
new_window = open('','video','width=500,height=390,menubar=no,status=no,location=no,toolbar=no,scrollbars=yes');
// open new document
new_window.document.open();
// Text of the new document
new_window.document.write("<html><head></head><body style='background-color:'black';margin-top:0; margin-right:0; margin-bottom:0; margin-left:0;'>");
new_window.document.write("<iframe width='560' height='315' src='https://www.youtube.com/embed/-linkRedacted-' frameborder='0' allow='autoplay; encrypted-media' allowfullscreen></iframe>");
new_window.document.write("</body></html>");
// close the document
new_window.document.close();
}
And in the body I have:
<a class="audio" href="javascript:void(0)" onclick="open_win()">
<img alt="See a demo video (opens in New window)" src="images/demo.jpg" width="120" height="110" /></a>
Is it an IE security zones issue, or a coding error?
Two things:
Are you using strict in your javascript? Maybe if you are using
strict IE11 does not like you calling a function without passing the
functions variables.
Is the javascript in a separate file. Maybe try copying your function right above your html to see if it makes a difference
Does anyone know why my code stops working in IE 11 when using tag like this:
<img blabla ng-src="{{test.bla.path }}">
I printed out the test.bla.path and did this:
<img blabla ng-src=" and I copied the text that top scope returned in here ">
and it worked. O.O
The image displays but I do things with this image after it loads but this just seems to not work on IE 11 if I do it like I did in first example, cause it works on every other browser.
This question already has answers here:
How to make HTML open a hyperlink in another window or tab?
(9 answers)
Closed 8 years ago.
How do I transform the first section of this document.write code into a popup link? Note the first part says "<a href=\"\/popups\/fed_budget.asp\"><img src=\"http:\/images\/video_graphic.jpg\, etc. How do I change that button link (video_graphic.jpg) to a popup instead of taking me to a different page? This is what I currently have:
document.write("<td width=\"251px\"><a href=\"\/popups\/fed_budget.asp\"><img src=\"http:\/images\/video_graphic.jpg\" alt=\"Video Graphic\" \/><\/a><\/td>");
document.write("<td style=\"padding-top:30px; padding-left:10px; padding-right:10px\">");
document.write("<b class=\"blue_text\">Recent News<\/b><br \/><br \/>");
document.write("<strong><a href=\"\/news\/newshub\/articles\/federal_budget_2014.asp\">Your Federal Budget Update<\/a> <\/strong> <b class=\"blue_text\">New<\/b><br \/>");
document.write("Read our run-down on the super side of this year's Budget.<br \/><br \/><br \/>");
document.write("<strong><a href=\"\/news\/newshub\/articles\/EOFY_Tips_tricks.asp\">EOFY tips and tricks<\/a><\/strong> <b class=\"blue_text\">New<\/b><br \/>");
document.write("Six strategies to help you get your super in shape.<br \/><br \/>");
document.write("<\/td>");
document.write("<\/tr>");
document.write("<\/table>");
Popup link? Did you mean open it in a new tab ?
Just add attribute target="_blank" to the a tag.
Something like:
<a target="_blank" href="..."><img src="..." /></a>
Ps.: Avoid using document.write
target=“_blank” vs. target=“_new”
HTML <a> target Attribute
If opening the link in another window is what you mean by "popup," the simplest thing for you to do would be to add a target attribute to your link, so it looks like this:
<img src="http://images/video_graphic.jpg" alt="Video Graphic"/>
If, instead, you want to open this in a simplified new window, you'll have to use a JavaScript click handler that calls window.open:
...
Oh, and I'd parrot the whole "don't use document.write ever" philosophy.
I am trying to print a page with window.print but it ain't working in all the browsers.
This is the code that i am using:
<div class="user_buttons">
<!--Test 1-->
<IMG SRC="images/print.png" BORDER="0"
<!--Test 2-->
<FORM>
<INPUT TYPE="button" onClick="window.print()">
</FORM>
<!--Test 3-->
<SCRIPT LANGUAGE="JavaScript">
if (window.print) {
document.write('<form><input type=button name=print value="Print" onClick="window.print()"></form>');
}
</script>
<!--Test 4-->
<img src="images/print.png" onclick="window.print()">
<div><img src="images/overzicht.png" title="Terug naar overzicht"></div>
</div>
As you can see i am trying multiple solutions given by the internet. What is frustrating is that those codes are working on the demo sites but they aren't on my page. I post my code in JSF. The JSF example will not be a working example but it will have the entire code in the javascript area. The link for the entire code is here: http://jsfiddle.net/7bRNu/
I finally got it. It was a very painfull process of searching errors in a huge mess of code. The next time you ask a question on stackoverflow, please make sure that you broke the problem down into smaller pieces and post only the code that you think is probably the cause of your problem.
In the very bottom of your entire code, there is a little script-section in which it says:
var print = document.getElementById("print").value;
You are in the global scope, meaning that every variable you declare will be a property of window. Therefore, by writing print = you actually redefine window.print. Change the name of this variable and you should be good. The following line is only an example. You can choose whatever variable name you like. Just don't use print.
var printValue = document.getElementById("print").value;
Here is one method isolated:
http://jsfiddle.net/5PumN/
<IMG SRC="images/print.png" BORDER="0"
It works just fine here.
I know that you can use a javascript: pseudo protocol for URLs in an <a> tag. However, I've noticed that Firefox and IE will both allow 'javascript:' to precede javascript code within a <script> tag. Is this valid syntax? Does it change the scoping rules?
Examples:
I've seen this many times:
<a onclick="javascript:alert('hello world!');">Hello World!</a>
But is this legal/valid syntax and does it do anything special:
<script type="text/javascript">
javascript:alert('hello world!');
</script>
Outside of the href attribute (where it is a protocol specifier), name: just creates a label (such as one might use with a continue or break).
See: Do you ever need to specify javascript: in an onclick?
You need the javascript: "protocol" when you want to put JavaScript in the href attribute of a link.
<!-- does not work -->
link
<!-- does work -->
link
<!-- also works -->
link
As far as I know (and please, if I'm wrong, someone correct me) there is no difference in scope, but there is a very important difference about this.
<!-- does not work -->
link
<!-- alerts "undefined" -->
link
<!-- works as expected, alerts "<url>#" -->
link
One thing to consider, our testers would always ding us if we did something like
<a href='javascript:openwindowmethod("url");'> stuff </a>
Rather than
<a href='url' onclick='return openwindowmethod(this.href);'> stuff </a>
The first method would only work if you click on it but not if you shift or alt clicked on it, or right clicked and went to open in a new window.
The second method would support all of that, as well as the ability to function the way it intended if the user just plain clicked the link.
The javascript: syntax can be used anywhere in a URL and executes the following string as a script. It is part of the HTML spec and AFAIK is supported by all current major browsers.