Rella
Rella

Reputation: 66935

Is it possible to open empty html popup with JS in it?

So we can do:

<html>
<head>
 <title>JavaScript Popup Example 3</title>
</head>

<script type="text/javascript">
function exitpop()
{
    my_window = window.open("", "mywindow1", "status=1,width=350,height=150");
    //my_window.document.write('somehow add JS'); 
    my_window.document.write('<h1>Popup Test!</h1><br/>'); 
    my_window.document.write('J_\alpha(x) = \sum_{m=0}^\infty \frac{(-1)^m}{m! \, \Gamma(m + \alpha + 1)}{\left({\frac{x}{2}}\right)}^{2 m + \alpha} ');
}
</script>

<body onunload="javascript: exitpop()" >
<h1>JavaScript Popup Example 4</h1>
</body>
</html>

but how to for example add to header of that html page with something like <script type="text/javascript" src="path-to-MathJax/MathJax.js"></script> to enable MathML and tex formulas rendering?

Upvotes: 3

Views: 7961

Answers (3)

Zer001
Zer001

Reputation: 619

You can consider using an iframe, you can set its head and body altogether, and you can put it in the window.

Upvotes: 1

Marcel
Marcel

Reputation: 28087

Yep, you just need to concatenate the script tags, like so: jsfiddle demo

The money-shot code sample is:

jswin = window.open("", "jswin", "width=350,height=150");
jswin.document.write("Here's your popup!");
jswin.document.write('<scr'+'ipt>alert("Here\'s your alert()!");</scr'+'ipt>');

Upvotes: 3

TimonWang
TimonWang

Reputation: 920

Use javascript to create a node named script, and sets it's attributes with javascript. Then append the node to document.head.

<html>
<head>
 <title>JavaScript Popup Example 3</title>
</head>

<script type="text/javascript">
function exitpop()
{
    var my_window = window.open("", "mywindow1", "status=1,width=350,height=150");


    var head = my_window.document.getElementsByTagName("head").item(0);
    alert(head.innerHTML);
      var script = my_window.document.createElement ("script");  
      script.src = "a.js";  
      head.appendChild (script);
    alert(head.innerHTML);
}
</script>

<body onunload="javascript: exitpop()" >
<h1>JavaScript Popup Example 4</h1>
</body>
</html>

Upvotes: 1

Related Questions