admin管理员组文章数量:1391955
I have a couple of questions:
Is
<iframe src="/index.php"></iframe>
the same as HTMLIFrameElement ?Why
<iframe src="data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t" height=1280 width=800></iframe>
works fine, but
a=document.getElementsByTagName('body')[0]; b=document.createElement('iframe'); b.src="data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t"; a.appendChild(b);
does not work? I mean in DOM HTMLIFrameElement src I could put function with encoded string. Is it possible to encode string only in src variable?
I have a couple of questions:
Is
<iframe src="/index.php"></iframe>
the same as HTMLIFrameElement ?Why
<iframe src="data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t" height=1280 width=800></iframe>
works fine, but
a=document.getElementsByTagName('body')[0]; b=document.createElement('iframe'); b.src="data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t"; a.appendChild(b);
does not work? I mean in DOM HTMLIFrameElement src I could put function with encoded string. Is it possible to encode string only in src variable?
- Just putting it here so everyone can see that the whole premise of your question is false. jsfiddle/JkJNH/2 <-- they work exactly the same, and that code is pretty much directly copypasted from your question. – Esailija Commented Dec 19, 2012 at 18:39
3 Answers
Reset to default 3- Yes
- You need to append the iFrame to the document. Like so
document.body.appendChild(b)
The Data URI scheme is for direct embedded data.
data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t
Means a html page with "http://example."
as its sole content.
You probably want "http://example."
as src
To your point 2: your two methods give the same result.
Live demo: http://jsfiddle/Ft9gh/
a=document.getElementsByTagName('body')[0];
b=document.createElement('iframe');
b.src="data:text/html;base64,aHR0cDovL2V4YW1wbGUuY29t";
a.appendChild(b);
本文标签: javascriptIframe source with variableStack Overflow
版权声明:本文标题:javascript - Iframe source with variable - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744681242a2619421.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论