Hi
I’m having problems getting my print button to work in IE. It works locally but when I put my pages live it doesnt work.
I’ve found many posts about this online but nobody seems to have an answer.
This is my code…
<script type="text/javascript">
/*Begin*/
function displayHTML(form) {
var inf2 = form.Box.value;
var inf3 = form.htmlBox1.value;
var inf4 = form.htmlBox2.value;
var inf5 = form.htmlBox3.value;
win = window.open("", 'popup', 'toolbar = yes, status = no');
win.document.write("" + "<H2>" + "<b>" + "My Action Plan" + "</H2>" + "<br>" + "My barrier:" + "</b>" + inf2 + "<br>" + "<br>" + "<b>" + "How will I remove/reduce this barrier?: " + "</b>" + inf3 + "<br>" + "<br>" + "<b>" + "When this is to be achieved by:" + "</b>" + inf4 + "<br>" + "<br>" + "<B>" + "Steps I am to take to achieve this: " + "</b>" + inf5 + "<br>" + "<br>" + "<html><head><title>popup</title></head><body><br><br>" + "<a href='print.html' onclick='window.print();return false;'>" + "<img src='images/printer.png' height='35px' width='132px' border='0'></a></body></html>" + "");
}
//-->
</script>
I’ve tried adding
win.window.print();
and
things like this…
window.focus();window.print();
self.focus();self.print();
Can anyone help?
Thanks
The inline event attributes have problems in IE (which is further evidence to not use them) so, use traditional event assignment techniques instead, where a script attaches the event to the appropriate element.
Put a suitable identifier on the link, and use a script to attach an onclick event.
Don’t forget to break apart the text version of </script> piece, otherwise IE will screw up and think that it ends your script.
win.document.write('<H2><b>My Action Plan</H2><br>' +
'My barrier: </b>' + inf2 + '<br><br>' +
'<b>How will I remove/reduce this barrier?: </b>' + inf3 + '<br><br>' +
'<b>When this is to be achieved by: </b>' + inf4 + '<br><br>' +
'<B>Steps I am to take to achieve this: </b>' + inf5 + '<br><br>' +
'<html>' +
'<head><title>popup</title></head>' +
'<body>' +
'<br><br>' +
'<a id="print" href="print.html"><img src="http://www.sitepoint.com/forums/images/printer.png" height="35px" width="132px" border="0"></a>' +
'<script type="text/javascript">' +
'var link = document.getElementById("print");' +
'link.onclick = function () {' +
'window.print();' +
'return false;' +
'};' +
'</scr' + 'ipt>' +
'</body>' +
'</html>');
Thank you for your help but unfortunetly its still not working. I’m thinking it may be easier to just put a sentence at the bottom of the page telling them to print it manually.
That’s a good idea - it’s the most compatible solution.