Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Javascript printing question

Javascript printing question

Scheduled Pinned Locked Moved Web Development
questionjavascripthtmltoolstutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jack Vanderhorst
    wrote on last edited by
    #1

    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>

    N D J 3 Replies Last reply
    0
    • J Jack Vanderhorst

      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>

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      Replace winPrint.print(); with this winPrint.document.execCommand("Print");


      I know the language. I've read a book. - _Madmatt

      J 1 Reply Last reply
      0
      • N Not Active

        Replace winPrint.print(); with this winPrint.document.execCommand("Print");


        I know the language. I've read a book. - _Madmatt

        J Offline
        J Offline
        Jack Vanderhorst
        wrote on last edited by
        #3

        Yes sir! Thank you, exactly what I needed

        1 Reply Last reply
        0
        • J Jack Vanderhorst

          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>

          D Offline
          D Offline
          daveyerwin
          wrote on last edited by
          #4

          Here is a way that works in more browsers ... winPrint.document.close(); winPrint.print();

          J 1 Reply Last reply
          0
          • D daveyerwin

            Here is a way that works in more browsers ... winPrint.document.close(); winPrint.print();

            J Offline
            J Offline
            Jack Vanderhorst
            wrote on last edited by
            #5

            Good to know, cheers :)

            1 Reply Last reply
            0
            • J Jack Vanderhorst

              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>

              J Offline
              J Offline
              Johnathan Cox
              wrote on last edited by
              #6

              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[^]

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups