The Wayback Machine - https://web.archive.org/web/20101003113626/http://answers.oreilly.com:80/topic/2097-display-text-in-separate-page-using-javascript-button/

Jump to content

Display text in separate page using Javascript button

Pharaoh8721's Photo
Posted Sep 26 2010 06:38 PM
238 Views

Can anybody help me to create a button in javascript that when you click on it, it will display text on another page and go to that page as well? I have been going crazy trying to figure it out. Thank You.

Tags:
1 Subscribe


2 Replies

0
  arjonesiii's Photo
Posted Sep 27 2010 07:37 AM

Here's an example. Paste the code below into a new text document and save it as Page1.htm. Then browse to the page you saved and click the button. It will open a second window containing the text "I got to page 2!"


<html><head><title>Page 1</title>
<script type="text/javascript">
function showPage2() {
w2 = window.open ("", "_blank", "scrollbars='yes', toolbar='yes', menubar='yes', resizeable='yes', status='yes',

titlebar='yes', location='yes'");
w2doc = w2.document;
w2doc.open("text/html","replace");
var txt="<html><body>I got to page 2!</body></html>";
w2doc.write(txt);
w2doc.title = "Page 2";
w2doc.close();

}

</script>
</head>
<body>
<form action="">
<p>Click the button below to display the text "I got to page 2!" in a separate window.</p>
<input type="button" value="Click for Page 2" onclick="showPage2();">
</form>
</body>
<html>
 : Sep 27 2010 10:56 AM
The code worked!! Thank you so much!!