Jump to content

Opening a web page created in another web page


DeadHeat

Recommended Posts

No I mean create a web page based off of the html code that the user writes in the textarea in the first webpage. So you have one web page with a textarea in it, the user writes html code in the textarea and when he clicks a button the code he wrote is used to create another webpage.

Link to comment
Share on other sites

Yes, it can be done with Javascript.

 

First, you need to access the textarea, using document.getElementById() and get its value, then open a new window and write to its document.

 

The Javascript function would look something like this:

function showHTML() {    var w = window.open();    w.document.open();    w.document.write(document.getElementById("myTextarea").value);    w.document.close();}

You could call the function when a button is clicked.

 

Here's a similar example on the W3Schools website, but without getting the HTML from a textarea: http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_doc_open2

Link to comment
Share on other sites

To close the window you call close() on the window object, not on the document. You'll also need a global reference to the window you created, right now, "w" is local to the function and can't be used outside of it.

Link to comment
Share on other sites

It won't work if the variable that contains the new window is local to the function, it needs to be accessible from other scopes. What code did you try?

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
×
×
  • Create New...