Jump to content

Copy <div> From One Page To Another


nicolet
 Share

Recommended Posts

In my site there is a page, say a.html, in which a <div> contains several lines of HTML code with about 20 tags. I'd like to have the content of that <div> inserted in other pages, say b.html and c.html when they get loaded. - I think, this is something for getElementById? How do I copy a <div> from one page to another?

Link to comment
Share on other sites

might be less hassle to store content in javascript array, and the call function to display its content// JavaScript Documentfunction showthis(divcontent){var text = new Array();//if content contains apostrophe use character code, or instead use '' or is it ''' or maybe \'text[0]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';text[1]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';text[2]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';document.write(text[divcontent]);}

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript" src="showhtml.js"></script></head><body><div><script type="text/javascript">showthis(0);</script></div><div><script type="text/javascript">showthis(1);</script></div><div><script type="text/javascript">showthis(2);</script></div></body></html>

Edited by dsonesuk
Link to comment
Share on other sites

might be less hassle to store content in javascript array, and the call function to display its content// JavaScript Documentfunction showthis(divcontent){var text = new Array();//if content contains apostrophe use character code, or instead use '' or is it ''' or maybe \'text[0]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';text[1]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';text[2]='<p>thumbnailLorem ipsum <span style="color: red">dolor sit amet</span>, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet <a href="http://www.w3schools.com/">dolore magna</a> aliquam erat volutpat.</p><p> Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> <p>Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui.</p>';document.write(text[divcontent]);}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /><title>Untitled Document</title><script type="text/javascript" src="showhtml.js"></script></head><body><div><script type="text/javascript">showthis(0);</script></div><div><script type="text/javascript">showthis(1);</script></div><div><script type="text/javascript">showthis(2);</script></div></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...