SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    print button not working in IE7

    Hi
    I'm having problems getting my print button to work in IE. It works locally but when I put my pages live it doesnt work.

    I've found many posts about this online but nobody seems to have an answer.

    This is my code....

    Code:
     <script type="text/javascript">
    
    /*Begin*/
    function displayHTML(form) {
    var inf2 = form.Box.value;
    var inf3 = form.htmlBox1.value;
    var inf4 = form.htmlBox2.value;
    var inf5 = form.htmlBox3.value;
    
    win = window.open("", 'popup', 'toolbar = yes, status = no');
    win.document.write("" +  "<H2>" + "<b>" + "My Action Plan" + "</H2>" +  "<br>" + "My barrier:" + "</b>" + inf2 + "<br>" + "<br>" + "<b>" + "How will I remove/reduce this barrier?: " + "</b>" + inf3 + "<br>" + "<br>" + "<b>" + "When this is to be achieved by:" + "</b>" + inf4 + "<br>" + "<br>" + "<B>" + "Steps I am to take to achieve this: " + "</b>" + inf5 + "<br>" + "<br>" + "<html><head><title>popup</title></head><body><br><br>" + "<a href='print.html' onclick='window.print();return false;'>" + "<img src='images/printer.png' height='35px' width='132px' border='0'></a></body></html>" + "");
    
    
     
    }
    	
    //-->	
      </script>
    I've tried adding

    win.window.print();


    and

    things like this....

    window.focus();window.print();
    self.focus();self.print();

    Can anyone help?

    Thanks

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The inline event attributes have problems in IE (which is further evidence to not use them) so, use traditional event assignment techniques instead, where a script attaches the event to the appropriate element.

    Put a suitable identifier on the link, and use a script to attach an onclick event.
    Don't forget to break apart the text version of </script> piece, otherwise IE will screw up and think that it ends your script.

    Code javascript:
    win.document.write('<H2><b>My Action Plan</H2><br>' +
        'My barrier: </b>' + inf2 + '<br><br>' +
        '<b>How will I remove/reduce this barrier?: </b>' + inf3 + '<br><br>' +
        '<b>When this is to be achieved by: </b>' + inf4 + '<br><br>' +
        '<B>Steps I am to take to achieve this: </b>' + inf5 + '<br><br>' +
        '<html>' +
            '<head><title>popup</title></head>' +
            '<body>' +
                '<br><br>' +
                '<a id="print" href="print.html"><img src="http://www.sitepoint.com/forums/images/printer.png" height="35px" width="132px" border="0"></a>' +
                '<script type="text/javascript">' +
                'var link = document.getElementById("print");' +
                'link.onclick = function () {' +
                    'window.print();' +
                    'return false;' +
                '};' +
                '</scr' + 'ipt>' +
            '</body>' +
        '</html>');
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Jun 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your help but unfortunetly its still not working. I'm thinking it may be easier to just put a sentence at the bottom of the page telling them to print it manually.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by katybaby View Post
    Thank you for your help but unfortunetly its still not working. I'm thinking it may be easier to just put a sentence at the bottom of the page telling them to print it manually.
    That's a good idea - it's the most compatible solution.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •