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
    Sep 2011
    Posts
    193
    Thanks
    147
    Thanked 0 Times in 0 Posts

    Copy table and open a new popup window

    Hello,

    I need the help of the experts here on this forum.

    Much thanks and appreciation for everyones help and support.

    What I would like to accomplish is, at the click of a button is to:

    1. copy the existing table below
    2. open a new popup window
    3. Use the document.write to write the table from the previous page onto the new popup page.

    Code:
    <!DOCTYPE html>
    
    <html>
    
    <head>
    
    <meta http-equiv="Content-Language" content="en-ca">
    
    </head>
    
    <body>
    
    <table id="data" border="1" cellspacing="1" width="100" id="table1">
    	<tr>
    		<th>Fruits</th>
    		<th>Vegetables</th>
    		<th>Colors</th>
    		<th>Quantity</th>
    		<th>Price</th>
    	</tr>
    	<tr>
    		<td>Apples</td>
    		<td>Carrots</td>
    		<td>red</td>
    		<td>10</td>
    		<td>0.99</td>
    	</tr>
    	<tr>
    		<td>Pears</td>
    		<td>Celery</td>
    		<td>blue</td>
    		<td>24</td>
    		<td>1.00</td>
    	</tr>
    	<tr>
    		<td>Mangos</td>
    		<td>Broccoli</td>
    		<td>green</td>
    		<td>12</td>
    		<td>1.50</td>
    	</tr>
    	<tr>
    		<td>Oranges</td>
    		<td>Cauliflower</td>
    		<td>purple</td>
    		<td>48</td>
    		<td>1.25</td>
    	</tr>
    </table>
    
    <br>
    
    <input type="button" value="test it"/>
    
    </body>
    
    </html>

  • #2
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    3,020
    Thanks
    56
    Thanked 566 Times in 563 Posts
    opening new windows can run into problems with popup blockers, but taking your request literally...

    Code:
    function openIt(){
    var cont=document.getElementById("data").outerHTML;
    var win = window.open();
    win.document.write(cont);
    }

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Unless you still have visitors using Netscape 4 you should no longer be using document.write.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • Users who have thanked felgall for this post:

    jason_kelly (08-28-2013)


  •  

    Posting Permissions

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