#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Halifax Nova Scotia Canada
    Posts
    5
    Rep Power
    0

    Question Javascript Print()


    I have a page divided up into two frames. The top frame contains information, while the bottom frame contians my navigation buttons and a print button. When a user clicks on the print button I have it set up to print the top frame. This works fine except that it closes the window when the printing starts. Does anyone know why it does this. I don't want the window to close. I do not have any code in there to cause the window to close. The print button is set up like this.

    <input type=image src="Graphics/print.jpg" name=cmdprint value=Print onClick=top.frames[0].CallPrint() border=0>

    In my top frame I have set up the following function.

    function CallPrint()
    {
    self.focus()
    self.print()
    }

    none of this script should close the window. Does anyone know if it is a bug of javascript, or is there something else happening.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    200
    Rep Power
    14
    Which OS/browser/version?

    Nothing in the refs on print doing anything dirty.

    How about that self.focus() ?
    Hmm, nah, probably nothing wrong with that either.
    It's close that doesn't work on individual frames, focus should work just fine.

    You're not using a print _button_ btw.

    Do you have "Display a notification about every script error" turned on?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Halifax Nova Scotia Canada
    Posts
    5
    Rep Power
    0
    Browser IE 5.5, haven't tried netscape 6 yet.

    I am just using a regular image button, the client did not want the buttons to display on the print out page, that is why I am using frames. I place my buttons on the bottom frame to control the top frame. So that when they print only the contents of the top frame gets printed. The focus is there for older browsers, I read that for IE 4 and Mac IE 4, the frame you want to print has to recieve focus first.

    I do have display notification turned on, but it is not returning anything, that is why I am stumped. It almost seems that the window is tied into the print window. Because when I hit cancel on the print window, that closes my browser as well. It is really wierd.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    200
    Rep Power
    14
    What happens if you try to print a normal webpage through File >> Print?

    What's in your File >> Page Setup.. ?

    Have you tried printing a normal webpage (no frames) with window.print()?

    Having some doubts about that self.print(). What exactly is self referring to? Ah, to the window I guess. Well, you could try window.print() instead, but I don't think there's a difference.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Halifax Nova Scotia Canada
    Posts
    5
    Rep Power
    0
    There is a difference between window.print() and self.print()

    Window.print() will print the entire window. Including the bottom frame with the buttons. self.print() prints just the frame with the focus. It is the same as saying top.frames[0].print().

    I have tried a left click and print on the frame window and that worked fine. It is just the javascript one that does it. I have also tried a simple test page with a self.print() no frames, and again it worked just fine. It is just this frames page.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    Location
    The Netherlands
    Posts
    200
    Rep Power
    14
    Does this work:

    Put this function in the onClick of your Print button

    function myprint()
    {
    window.parent.frames[0].focus();
    window.print();
    }


    (yes, I know you said that window.print prints the entire window, but it really shouldn't do this cause your frame == window)

    -------------
    I found some examples on the net and they all say that if you want to print frame B, you have to call the print function from frame A. Doesn't make any sense to me, but perhaps that is what's causing your problem.

IMN logo majestic logo threadwatch logo seochat tools logo