Skip to content

Instantly share code, notes, and snippets.

@NTMan
Created May 10, 2015 21:22
Show Gist options
  • Save NTMan/3b6815cd5dbff935694e to your computer and use it in GitHub Desktop.
Save NTMan/3b6815cd5dbff935694e to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
<![CDATA[
]]>
</style>
</head>
<body>
<script>
<![CDATA[
pr_header = '<?xml version="1.0" encoding="UTF-8"?> \n\
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> \n';
pr_cont = '<html xmlns="http://www.w3.org/1999/xhtml"> \n\
<head> \n\
<style> \n\
<!-- \n\
body {background-color: blue; color: yellow;} \n\
--> \n\
</style> \n\
<style> \n\
body {margin-left:50%} \n\
</style> \n\
</head> \n\
<body> \n\
<h1>Hello world!!!</h1> \n\
</body> \n\
</html>';
function printfoobarHTML() {
var iframe = document.getElementById('printframe');
var doc = iframe.contentWindow.document
doc.open();
doc.write(pr_header + pr_cont);
doc.close();
}
function printfoobarXHTML() {
var iframe = document.getElementById('printframe');
iframe.contentWindow.location = 'data:application/xhtml+xml; charset=utf-8,' + pr_header + pr_cont;
}
function printfoobardiv() {
var div = document.getElementById('printdiv');
div.innerHTML = pr_cont;
}
function frload() {
//var iframe = document.getElementById('printframe');
//alert(iframe.contentWindow.document.origin);
//iframe.contentWindow.print();
}
]]>
</script>
<iframe id="printframe" name="printframe"></iframe>
<div id="printdiv"></div>
<button onclick="printfoobarHTML()">Print HTML</button>
<button onclick="printfoobarXHTML()">Print XHTML</button>
<button onclick="printfoobardiv()">Print DIV</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment