通过添加的Javascript来IFRAME DOM [英] Adding IFRAME to DOM by Javascript

查看:101
本文介绍了通过添加的Javascript来IFRAME DOM的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加 IFRAME 页面。这 IFRAME 应该是指一个URL。我加了下面code到HTML页面,但它不工作:

 使用document.createElement('< IFRAME SRC =HTTP://example.com'>< / IFRAME>');


解决方案

在这里你去:

  VAR IFRAME;IFRAME =使用document.createElement('IFRAME');
iframe.src ='http://example.com/file.zip';
iframe.style.display =无;
document.body.appendChild(IFRAME);

现场演示: http://jsfiddle.net/USSXF/2/

因为,您将整个HTML串入的createElement 功能(jQuery的风格你的code不起作用: )),这是无效的。此功能的有效参数重新$ P $字符串psenting标签名称(如'格'IFRAME'p'等)。

阅读关于使用document.createElement 在这里。

I want to add an iframe to the page. This iframe should refer to a URL. I added the below code to page HTML, but it doesn't work:

document.createElement('<iframe src='http://example.com'></iframe>');

解决方案

Here you go:

var iframe;

iframe = document.createElement('iframe');
iframe.src = 'http://example.com/file.zip';
iframe.style.display = 'none';
document.body.appendChild(iframe);

Live demo: http://jsfiddle.net/USSXF/2/

Your code doesn't work because you're passing an entire HTML string into the createElement function ("jQuery style" :)), which is invalid. The valid parameter for this function is a string representing the tag-name (like 'div', 'iframe', 'p', etc.).

Read about document.createElement here.

这篇关于通过添加的Javascript来IFRAME DOM的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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