Is it possible to open an 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, for example, to add something like to the header of this html page <script type="text/javascript" src="path-to-MathJax/MathJax.js"></script>to enable rendering of MathML and tex formulas?

+3
source share
3 answers

Yes, you just need to concatenate the script tags, for example: jsfiddle demo

Sample Money Shot Code:

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

Use javascript to create a node named script and set attributes with javascript. Then add 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>
+1
source

You can use an iframe, you can set its head and body as a whole, and you can put it in a window.

+1
source

Source: https://habr.com/ru/post/1795968/


All Articles