比如说,我想通过javascript的document.write 句语,向网页里输入 <script>location.href='';</script> 这句话,我该怎么写?
我试了半天,也不行,就是因为输入的内容有<script>
麻烦懂的高手帮帮忙,告诉一下

解决方案 »

  1.   

    document.write("<script>location.href='';"+"</"+"script>")
    这样试试呢。。
      

  2.   

    要转义的
    document.write("\<script\>location.href='http://www.baidu.com';\</script\>");
      

  3.   

    这个只能动态创建
    var js=document.createElement("SCRIPT")
    js.innerHTML="location.href='';"
    document.body.appendChild(js);
      

  4.   

    并非因为有<script>,而是因为有</script>
    如果你的JS中出现</script>,则不管它在什么位置出现,都认为是对前面一开始探测到的<script> 的结束,哪怕它是写在注释行中的。
    这样,你的document.write的东西就没用了。
    另外,在网页初始化时,就要找script中的对象,如 过程名,如果找不到,它不会在生成网页后再去找一遍,因此,你用document.write 写入网页的代码,不能被调用。
      

  5.   

     我的本意,就是当我点击一个连接的时候,这个连接的onclick事件,触发一个js函数
    这个js函数就是把此连接,放到<script>location.href='';</script>中,然后再置剪切板中,
    这样我直接点粘贴,就可以复制这个生成的地址了.哪位高手会?帮帮我小弟啊
      

  6.   

    <script>
    alert(decodeURIComponent("%3Cscript%3Elocation.href%3D''%3B%3C%2Fscript%3E"));
    document.write("&#60;&#115;&#99;&#114;&#105;&#112;&#116;&#62;&#108;&#111;&#99;&#97;&#116;&#105;&#111;&#110;&#46;&#104;&#114;&#101;&#102;&#61;&#39;&#39;&#59;&#60;&#47;&#115;&#99;&#114;&#105;&#112;&#116;&#62;&#32;")
    </script>
      

  7.   

    楼主不是舍近而求远吗?为什么不直接 location=''
      

  8.   


    document.write("<script>location.href=\'" + this.href + "\';<\/script>");