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 3 of 3
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Posts
    231
    Thanks
    9
    Thanked 1 Time in 1 Post

    Printing from inside the iframe

    I have an iframe which needs to be printed. What is the proper way of printing the inside content of the iframe, through a link Inside this iframe?

    Thx,
    Erind

  • #2
    New Coder
    Join Date
    Nov 2004
    Posts
    55
    Thanks
    8
    Thanked 2 Times in 1 Post
    I would assume that you'd have to do it from inside the iframe. you could just add:
    <a href="javascript:window.print()">Print Me</a>
    to the iframes page and that should work

  • #3
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    I tried this really fast because I was interested to see if you could print from outside the iframe:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Example</title>
    <script type="text/javascript">
    <!--
    function printFrame(n)
    	{
    	if (document.getElementById(n).print) document.getElementById(n).print();
    	else if (window.frames[n].print) window.frames[n].print();
    	else if (top.frames[n].print) top.frames[n].print();
    	}
    // -->
    </script>
    </head>
    <body>
    
    <a href="javascript:printFrame('my_iframe')">Print iframe</a>
    <br /><br />
    <iframe name="my_iframe" id="my_iframe" src="http://www.google.com"></iframe>
    
    </body>
    </html>
    What I found:
    - the DOM object reference doesn't contain a print function
    - the frames array reference does contain a print function, but I get "Access Denied" in IE and "Permission Denied" in FF, which makes sense

    Looks like you'll need to add the link to the iframed page itself (as dusty suggested).


  •  

    Posting Permissions

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