如何将 <script> 加载到 iframe 中? [英] how can i load <script>'s into an iframe?
本文介绍了如何将 <script> 加载到 iframe 中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经将逻辑从父级附加到我的 iframe 中
I've got the logic working to append into my iframe from the parent
这有效:
$('#iframe').load(function() {
$(this).contents().find('#target').append('this text has been inserted into the iframe by jquery');
});
这没有
$('#iframe').load(function() {
$(this).contents().find('body').append('<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>');
});
.lf
问题与插入的脚本标签没有正确转义有关.一半的 javascript 在 html 中变得可见,就像第一个脚本标签突然结束一样.
推荐答案
也许错误出在你的字符串上,永远不要在 javascript 中创建一个带有文字 < 的字符串./script> 在里面.
Maybe the error is with your string, never create a string in javascript with a literal < /script> in it.
$('#iframe').load(function() {
$(this).contents().find('body').append('<scr' + 'ipt type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></scr' + 'ipt>');
});
这篇关于如何将 <script> 加载到 iframe 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文