0

I have the following javascript variable with HTML code in it:

var html_ticket = '<!doctype html>' +
'<html dir="ltr" lang="en" class="no-js">' +
'<head> ' +
'   <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> ' +

'   ...... ' +

'</body> ' +
'</html> ';

I would like to open that variables content as a HTML in a new window.

Is this possible or am i approaching it wrong?

Regards

Egidi
  • 1,736
  • 8
  • 43
  • 69
  • Who knows, we haven't seen your approach yet, just a variable containing a string. – Teemu Oct 05 '14 at 16:57
  • i can't find anything on the net on how to achieve this, that's why i am wondering if this is possible... – Egidi Oct 05 '14 at 17:00

2 Answers2

2

of course you can: take a look here:

Open a new tab with custom HTML instead of a URL

var newWindow = window.open();
var html_ticket = '<html>...</html>';

newWindow.document.write(html_ticket);

JS Fiddle demo

Community
  • 1
  • 1
Ivan Hanák
  • 2,214
  • 1
  • 16
  • 25
2

You simply use a code like so

var newWindow = window.open();
var html_ticket = '<html>...</html>';

newWindow.document.write(html_ticket);
kilmer
  • 21
  • 3