是否有可能“伪造” iframe的src属性? [英] Is it possible to "fake" the src attribute of an iframe?
问题描述
我尝试使用JavaScript动态地将iframe添加到网页中。我想知道是否可以通过URL使用另一个html文件来设置我的iframe的src属性。
我的意思是有一种方法用JS变量伪造src属性文件的html,我可以设置我的代码(JS本身)吗?
我会使用DOM createElement在jQuery中创建iframe。
I try to add dynamically an iframe to a web page using JavaScript. I would like to know if that's possible to set the src attribute of my iframe without using another html file via an URL. I mean is there a way to "fake" the html for the src attribute file with a JS variable where we I can set my code (which is JS itself) ? I would use the DOM createElement to create the iframe in jQuery.
谢谢!
推荐答案
您可以查看 数据:
URI 。
You could look into data:
URIs.
<iframe src="data:text/html, .... URLencoded HTML data ....">
或者
<iframe src="data:text/html;base64, .... base64 encoded HTML data ....">
IE> = 8 (MSDN来源),Firefox,Safari 3+和Opera。
The scheme is supported by IE >= 8 (MSDN source), Firefox, Safari 3+ and Opera.
它有不同的长度限制。据说歌剧院大约4千字节; Internet Explorer为32千字节。 Firefox没有明确的长度限制。
It has differing length limits. Opera is said to cut off at about 4 kilobytes; Internet Explorer at 32 kilobytes. Firefox has no explicit length limit.
更多关于数据URI和转换工具的信息 Mozilla开发者中心
More on data URIs and tools for converting at Mozilla Developer Central
这篇关于是否有可能“伪造” iframe的src属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!