gpt4 book ai didi

JavaScript 在 document.write 中嵌入 <script> 标签不起作用

转载 作者:数据小太阳 更新时间:2023-10-29 05:50:06 26 4
gpt4 key购买 nike

我不确定我的代码有什么问题,但是当我尝试添加 actorWin.document.write('<script type=\"text/javascript\"><\/script>') 时一切都搞砸了。没有这一行,代码工作正常。

<!DOCTYPE html>
<meta charset="utf-8">
<title>create a window</title>

<script type='text/javascript'>
function Movie(title, actor) {
this.title = title;
this.actor= actor;
}
</script>
</head>
<body>
<script type='text/javascript'>

var documentary = new Movie('http://www.imdb.com/title/tt0358456/?ref_=fn_al_tt_2','http://en.wikipedia.org/wiki/Joaquin_Phoenix');
var movieWin = new Object();
var actorWin = new Object();

newWin=window.open('','Win','width=300,height=200,top=100,left=600');

newWin.document.write(
"<script type='text/javascript'>" +
"function PopUpWindowMovie(url) {" +
"movieWin=window.open(url,'','height=600,width=800,left=400,top=100,scrollbars,status,resizable');" +
"movieWin.focus();}" +
"function PopUpWindowActor(){" +
"actorWin=window.open('','','height=600,width=800,left=400,top=100,scrollbars,status,resizable');" +
"actorWin.focus(); " +
"actorWin.document.write('Joaquin Phoenix is a great actor and a long time vegan.<br />');" +
"actorWin.document.write('<script type=\"text/javascript\">" +
"function test() {" +
"alert(\"here\");" +
"} <\/script>');" +
"}" +
"<\/script>");
newWin.document.write("This is a MUST SEE movie: <h1>Earthlings (2005)</h1>");
newWin.document.write("<a href=\"javascript:PopUpWindowMovie('"+documentary.title+"')\">Go to see the movie info</a><br />");
newWin.document.write("<a href=\"javascript:PopUpWindowActor()\">Go to see the lead actor</a>");
</script>

</body>
</html>

最佳答案

只需更改其他脚本标签内的关闭脚本标签即可欺骗浏览器。

改变:

actorWin.document.write('<script type=\"text/javascript\"><\/script>')

到:

actorWin.document.write('<script type=\"text/javascript\"><\/scr'+'ipt>')

编辑:

完整代码:

 newWin.document.write(
"<script type='text/javascript'>" +
"function PopUpWindowMovie(url) {" +
"movieWin=window.open(url,'','height=600,width=800,left=400,top=100,scrollbars,status,resizable');" +
"movieWin.focus();}" +
"function PopUpWindowActor(){" +
"actorWin=window.open('','','height=600,width=800,left=400,top=100,scrollbars,status,resizable');" +
"actorWin.focus(); " +
"actorWin.document.write('Joaquin Phoenix is a great actor and a long time vegan.<br />');" +
"actorWin.document.write('<script type=\"text/javascript\">" +
"function test() {" +
"alert(\"here\");" +
"} <\/scr'+'ipt>');" + // <-- I've edited this line
"}" +
"<\/script>");
newWin.document.write("This is a MUST SEE movie: <h1>Earthlings (2005)</h1>");
newWin.document.write("<a href=\"javascript:PopUpWindowMovie('"+documentary.title+"')\">Go to see the movie info</a><br />");
newWin.document.write("<a href=\"javascript:PopUpWindowActor()\">Go to see the lead actor</a>");

关于JavaScript 在 document.write 中嵌入 &lt;script&gt; 标签不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19578244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com