如何在javascript代码中编写脚本标记? [英] How to write a script tag inside a javascript code?

查看:98
本文介绍了如何在javascript代码中编写脚本标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在iframe中调用的javascript代码。我想在javascript代码中添加一个标记,并将标记附加到iframes父体。这是我添加脚本标记并附加到iframe父体的代码。

I have a javascript code which is called inside an iframe. I want to add a tag inside that javascript code and append the tag to the iframes parent body. This is my code to add the script tag and append to iframes parent body.

setTimeout(function () {
         var scriptTag = "<script>alert(1)<";
         scriptTag +=  "/script>";
         $("#iframe").contents().find("body").append(scriptTag);
    }, 5000);

代码无效,既没有添加脚本标签也没有显示任何错误

the code isn't working it neither added the script tag nor showed any error

推荐答案

这可能会有所帮助

setTimeout(function () {
     var scriptTag = "<script>alert(1)</" + "script>";
     $("#iframe").contents().find("body").append(scriptTag);
}, 5000);

这篇关于如何在javascript代码中编写脚本标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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