Javascript printing question
-
In Javascript I am trying to create a new window, write some html into it, and then bring up the print dialog for this newly created window automatically. The follow code demonstrates what I am trying to do, the new window appears and is successfully written to but the print dialog does not show up. What gives?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Printing Example</title><script type="text/javascript" language="javascript">
function HelloPrint()
{
var winPrint = window.open("", "");
winPrint.document.write("<H3>Hello World</H3>");
winPrint.print();
}</script>
</head><body>
<a href="" onclick="HelloPrint()">Go</a>
</body>
</html> -
In Javascript I am trying to create a new window, write some html into it, and then bring up the print dialog for this newly created window automatically. The follow code demonstrates what I am trying to do, the new window appears and is successfully written to but the print dialog does not show up. What gives?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Printing Example</title><script type="text/javascript" language="javascript">
function HelloPrint()
{
var winPrint = window.open("", "");
winPrint.document.write("<H3>Hello World</H3>");
winPrint.print();
}</script>
</head><body>
<a href="" onclick="HelloPrint()">Go</a>
</body>
</html>Replace
winPrint.print();
with thiswinPrint.document.execCommand("Print");
I know the language. I've read a book. - _Madmatt
-
Replace
winPrint.print();
with thiswinPrint.document.execCommand("Print");
I know the language. I've read a book. - _Madmatt
Yes sir! Thank you, exactly what I needed
-
In Javascript I am trying to create a new window, write some html into it, and then bring up the print dialog for this newly created window automatically. The follow code demonstrates what I am trying to do, the new window appears and is successfully written to but the print dialog does not show up. What gives?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Printing Example</title><script type="text/javascript" language="javascript">
function HelloPrint()
{
var winPrint = window.open("", "");
winPrint.document.write("<H3>Hello World</H3>");
winPrint.print();
}</script>
</head><body>
<a href="" onclick="HelloPrint()">Go</a>
</body>
</html>Here is a way that works in more browsers ... winPrint.document.close(); winPrint.print();
-
Here is a way that works in more browsers ... winPrint.document.close(); winPrint.print();
Good to know, cheers :)
-
In Javascript I am trying to create a new window, write some html into it, and then bring up the print dialog for this newly created window automatically. The follow code demonstrates what I am trying to do, the new window appears and is successfully written to but the print dialog does not show up. What gives?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Printing Example</title><script type="text/javascript" language="javascript">
function HelloPrint()
{
var winPrint = window.open("", "");
winPrint.document.write("<H3>Hello World</H3>");
winPrint.print();
}</script>
</head><body>
<a href="" onclick="HelloPrint()">Go</a>
</body>
</html>Java is a complete programming language. In contrast, JavaScript is a coded program that can be introduced to HTML pages. These two languages are not at all inter-dependent and are designed for different intent. Java is an object-oriented programming (OOPS) or structured programming languages like C++ or C whereas JavaScript is a client-side scripting language. Web Design Brisbane - Experienced Digital Agency Brisbane[^]