JavaScript嵌入< script>document.write中的标签不起作用 [英] JavaScript embedding <script> tags in document.write not working

查看:34
本文介绍了JavaScript嵌入< script>document.write中的标签不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm not sure what is wrong with my code, but when I try and add actorWin.document.write('<script type=\"text/javascript\"><\/script>') everything gets screwed up. Without this line, the code works fine.

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

推荐答案

只需将其他脚本标签中的关闭脚本标签更改为傻瓜浏览器即可.

Just change closing script tag inside other script tag to fool browser.

更改:

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嵌入&lt; script&gt;document.write中的标签不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆