REGISTER FREE to Receive Instant Job

Tuesday, 18 November 2014

Opening a Popup and Print window at center of the screen

You can open popup and Print window through javascript. But opening it at center of the screen will make it look good for all size of screen and print page. Following is the way to do it.

Copy Code and Run...

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">    
function PrintDiv() {  
var divToPrint = document.getElementById('divToPrint');
var width = 400;
var height = 300;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
var popupWin = window.open('', '_blank', windowFeatures);
popupWin.document.open();
popupWin.document.write('<html><body onload="window.print()">' + divToPrint.innerHTML + '</html>');
popupWin.document.close();
}
</script>
</head>
<body >
other contents
<div id="divToPrint">
<div style="width:200px;height:300px;background-color:teal;">
This is the div to print
</div>
</div>
<div>
<input type="button" value="print" onclick="PrintDiv();"/>
</div>
</body>
</html>


1 comment:

  1. Thanks for sharing this great. Keep sharing more useful and conspicuous stuff like this. Thank you so much
    192.168.l.l

    ReplyDelete

Popular Posts

Powered by Blogger.

About Me

My photo

JobsAcid is a 'job search engine' to provide finding a job on the internet easier for the user. It has designed as huge selection of job offerings on the same search engine.