Reputation: 55
I have simple code which creates a popup and add a text, which is working fine:
<!DOCTYPE html><html><body><script src='./js/jquery.min.js'></script><script>var blade = window.open("", "BLADE", "width=500, height=500, scrollbars=yes, resizable=yes");$(blade.document.body).html("<!DOCTYPE html><html><body>this is my 'content'</body></html>");</script></body></html>
the issue is when I add into child (new html) a line to load jquery as well:
<!DOCTYPE html><html><body><script src='./js/jquery.min.js'></script><script>var blade = window.open("", "BLADE", "width=500, height=500, scrollbars=yes, resizable=yes");$(blade.document.body).html("<!DOCTYPE html><html><body><script src='./js/jquery.min.js'></script>this is my 'content'</body></html>");</script></body></html>
then popup is not created and on main-page I can see: this is my 'content'");
When checking js console I can see in this instance also: Uncaught SyntaxError: Unexpected token ILLEGAL
I would be grateful for helping me out how to add jquery to pop-up html window code.
Upvotes: 0
Views: 1023
Reputation: 8171
You need to escape your end script tag, like below:
$(blade.document.body).html("<!DOCTYPE html><html><body><script src='./js/jquery.min.js'><\/script>this is my 'content'</body></html>");
</script>
to <\/script>
Also, you don't need "<!DOCTYPE html><html><body>"
in your append as it's pointless since your target node is body
already!
Upvotes: 1
Reputation: 207501
It is the classic case of the </script>
inside the string closing the outside script block.
></scr" + "ipt>th
<!DOCTYPE html>
<html>
<body>
<script src='./js/jquery.min.js'></script>
<script>
var blade = window.open("", "BLADE", "width=500, height=500, scrollbars=yes, resizable=yes");
$(blade.document.body).html("<!DOCTYPE html><html><body><script src='./js/jquery.min.js'></sc" + "ript>this is my 'content'</body></html>");
</script>
</body>
</html>
Upvotes: 2
Reputation: 87
Looks like the link to your JS file might not be working. There shouldn't be a './' unless your 'js' folder is within a folder called '.', which I doubt.
Double check that you're linking to the correct file, maybe even try linking to a hosted version of it (below) just to be sure that's the problem.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
Upvotes: 0