0

Suppose I regex a string in Javascript and save it in a var.

So my string would be something like :

var reg= "<html><body>..... </body></html>"

or only

var reg= "<body>....</body>

How do I make this string into HTML document that I would be able to display somewhere from a Javascript function.

rahul888
  • 413
  • 2
  • 8
  • 18
  • 2
    [**TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ**](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – adeneo Nov 28 '13 at 17:10

2 Answers2

2
var win = window.open('');
win.document.write(reg);
Barmar
  • 741,623
  • 53
  • 500
  • 612
0

You can use javascript document.write(). You can use this command to output string that can be a html element or even a javascript code, or css etc.

Sure that you can try things like that:

document.write("<body><div>a</div></body>");

Then you transform your whole page into that.

Or even can you write in a iFrame or a Window, Dialog...

newWindow = window.open("");
newWindow.document.write("<body><div>a</div></body>");

...

newDialog = window.openDialog("");
newDialog.document.write("<body><div>a</div></body>");

I tried with the iFrame but i didnt found the write function into it, unhappily. But you can create element using var div = document.createElement("div") for example and after that you can .appendChild(div) in the iFrame easily this way:

var iframe = document.createElement("iframe");
iframe.id = 'iFrame';
var stringElement = "div";
var div = document.createElement(stringElement);
iframe.appendChild(div);
document.body.appendChild(iframe);

You have too window.showModalDialog() but i dont know how it works kk.

Paulo Roberto Rosa
  • 3,071
  • 5
  • 28
  • 53