SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Santos L Halper Zenith's Avatar
    Join Date
    May 2002
    Location
    Finland
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.print() in new window does nothing

    I need to open a new window from an ASP page to give user a chance to print some data with "printer friendly" a.k.a without any graphics. Problem is, the print-function does nothing. Here's the code:

    Code:
    function pikkuIkkuna()
    {
       mywin=window.open("","Tulostusversio","toolbar=no,height=445,width=775,location=no,status=no,menubar=no,scrollbars=no,resizeable=no");
       mywin.document.write ("<html><head><title>Tulostusversio</title></head><body>");
       mywin.document.write ........[other stuff].........
       mywin.document.write ("<tr><td colspan='2'><br><br><a href="javascript:window.print(this)">Print</a>td></tr>");
    }
    If I open the link in new window, printing dialog opens immediately. But now clicking it does nothing. Also - when clicking the browser's Print-button (after enabling the toolbar) printing goes fine. So the problem is with the javascript.

    I've tried:
    - self.print
    - document.print
    - something like referencewin.print (dont remember exactly but it didnt work anyways)

    I also tried to find solution from here with search but didn't find anything to solve this out.

    Since I'm using document.write i cannot put any js-script inside the window, or I get this error:

    Nested Script Block
    A script block cannot be placed inside another script block.

    Thanks in advance.

    -Z-

  2. #2
    SitePoint Member
    Join Date
    Apr 2003
    Location
    Dublin, Ireland
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    instead of:
    <a href="java script:window.print(this)">Print</a>

    try:
    a href="javascript:window.print()">Print</a>

    there is no space needed between 'java' and 'script', and the print function doesn't require any arguements.

    Also, although it shouldn't affect the script, you're missing an opening bracket on the 'td' tag:

    this)">Print</a>td></tr>


    .:bar:.

  3. #3
    Santos L Halper Zenith's Avatar
    Join Date
    May 2002
    Location
    Finland
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was written java_script but this forum software put the space there. I still don't like this the older one was so much better

    I tried to solve this and asked advices from many forums & used Gogole but since I got nothing I had to do it all over again. Netscape 6 worked fine, but I found no solution for IE (6).

    This printing worked fine when I made a new page which I opened. So I didn't use document.write, only mywin = window.open("page.asp".....)

    When I put that same window.print() -script to page.asp, it works fine.

    Damn Microsoft, I would have saved work and cigarettes again if had known...

    -Z-

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you must use

    mywin.document.close()

    after writing all the HTML to effectively close the IO stream. That should allow window.print() to work
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Santos L Halper Zenith's Avatar
    Join Date
    May 2002
    Location
    Finland
    Posts
    641
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I tried that too but it didn't help.

  6. #6
    SitePoint Addict
    Join Date
    Aug 2001
    Location
    Los Angeles, CA
    Posts
    346
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    mywin.print();


Bookmarks

Posting Permissions

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