Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Code Dosent work any Idea Why?

    Hi all,

    I was givent this code and it dosent work and I dont have enough expirence to know why, can anyone help or is it even possible to do this?

    My intent is that when clicking on this link it prings up a page that is printable and then closes the window afterwards.

    </FORM>


    <SCRIPT LANGUAGE="JavaScript">
    function OpenPrintPage()
    {
    var wNew = window.open("PrintAndClose.htm","junkWindow");
    }
    </script>

    <form> <p align=center>
    <input type=button name=print value="Print the SETR Chart"
    onClick="OpenPrintPage()">
    </form>

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    Worked for me.
    OracleGuy

  • #3
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, all this code does is open a new window... that's it.

    Originally posted by Pc__girl
    My intent is that when clicking on this link it prings up a page that is printable and then closes the window afterwards.
    Closes the window after what? After it prints? There's no way for JavaScript to know when the page has been printed. You can have this script open the appropriate printer-friendly page, and on that page have a script that opens the print dialog, but the user will have to close the window manually.

    On the other hand, the next closest thing would be to have the new window open, that window opens a print dialog, and then moves itself to the background, and using setTimeout() to close the window after a number of seconds... but you won't know if the user is modifying his printing preferences (which I do on a regular basis), so it may be hard to calculate when to close the window.

    Personally, I would leave the thinking to the users. It might not be a good idea to take that decision-making process away from them...

  • #4
    New Coder
    Join Date
    Jan 2004
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is quite simple actually

    on the page that opens the window simply have your script that opens the window your open window function
    <script>
    function mywindow(myloc,myname){
    window.open(myloc,myname)
    }
    </script>

    onClick="mywindow('printpage.htm','junkwindow')"

    on the page you want to print insert the following code into the
    onLoad of the body

    <body onLoad="window.print();window.close();">

    that is what i do anyways. but if you notice that it isn't printing the page properly remove the onload from the body and at the bottom of the page insert this code
    <script>
    window.print();
    window.close();
    </script>

    this should work if th onload doesn't

  • #5
    New to the CF scene
    Join Date
    Jan 2004
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thanks

    Hi all I told you I didnt know what I was doing I gave you the wrong script it was to have been this. Ill try what was suggest and see what happens.
    Thanks!
    <script language="JavaScript">
    function DoPrint()
    {
    if(window.print)
    {
    var strOut;
    if (navigator.appName == "Netscape")
    {
    strOut = "Be sure to use the Landscape setting!\n\n"
    + "Unfortunately, Netscape's scripting is not as capable as Internet Explorer's.\n"
    + "Netscape users must manually close this 'Printable SETR Image' page.\n"
    + " via File->Close Window.";
    }
    else
    {
    strOut = "Be sure to use the Landscape setting! Are you printing in color?";
    }

    alert (strOut);
    window.print();
    }
    }

    function AfterPrint()
    {
    // It seems we absolutely MUST have a dialog here.
    // Otherwise, the print job never happens ):
    // Maybe we could locate some kind of 'Sleep' function
    // to force a small pause that doesn't depend on the user
    // to interact with us.
    alert ("'OK' to finish print job....");

    window.close();
    }
    </script>

  • #6
    Regular Coder
    Join Date
    Aug 2002
    Location
    Silicon Valley, CA
    Posts
    980
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Thanks

    Originally posted by Pc__girl
    + "Unfortunately, Netscape's scripting is not as capable as Internet Explorer's.\n"
    AH-HAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHAHA!!!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •