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 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    document.body.innerHTML = originalContents;

    Is there a way to have the page reload when using this code

    document.body.innerHTML = originalContents;

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    I don't get it. If you are going to have the page reload, then why do you *need* to use innerHTML to assign the original contentes? Won't the reload do that for you?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Apologize for not being a little clearer.

    I am using this code to print contents of a DIV tag on my page.

    <script>function printDiv(divName) {
    var printContents = document.getElementById(divName).innerHTML;
    var originalContents = document.body.innerHTML;

    document.body.innerHTML = printContents;

    window.print();

    document.body.innerHTML = originalContents;

    }</script>

    With this button to print the Div

    <input type="button" onclick="printDiv('printableArea')" value="print bracket" />

    Worked like a charm to print but on the original contents lost some functionality on my menu bar (drop down menus did not appear). So I wanted to see if I could add a reload command that would restore the functionality.

    After playing with awhile found that simply adding

    location.reload(true);

    to the end of the script makes it work as intended.

    Thanks for the reply!

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,021
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    May I suggest that, instead, you get rid of that really really ugly way of creating the print content???

    Instead, just do something like this:
    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <style type="text/css">
    @media screen {
        .screenstuff { display: block; }
        .printstuff { display: none; }
    }
    @media print {
        .screenstuff { display: none; }
        .printstuff { display: block; }
    }
    </style>
    </head>
    <body>
    <div class="screenstuff">
        This content will appear only on the screen; it won't be printed.
    </div>
    <div>
        This content will appear on both the screen and in the printed page.
    </div>
    <div class="printstuff">
        You won't see this content on the screen, but it will print.
    </div>
    <div class="screenstuff">
        And more stuff only on the screen.
        <hr/>
        <input type="button" value="print" onclick="window.print();" />
    </div>
    </body>
    </html>
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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