是否有可能用JS打开空的html弹出窗口?

时间:2011-03-03 08:15:47

标签: javascript html popup

所以我们可以这样做:

<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>

但是如何使用类似<script type="text/javascript" src="path-to-MathJax/MathJax.js"></script>的内容添加到该html页面的标题以启用MathML和tex公式渲染?

3 个答案:

答案 0 :(得分:3)

是的,你只需要连接脚本标签,如:jsfiddle demo

拍摄的代码示例是:

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

答案 1 :(得分:1)

使用javascript创建一个名为script的节点,并使用javascript设置它的属性。然后将节点附加到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>

答案 2 :(得分:1)

你可以考虑使用iframe,你可以完全设置它的头部和身体,你可以将它放在窗口中。