开发者

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开发者_Go百科="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?


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>');


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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜