Home >Web Front-end >JS Tutorial >JS dynamically adds iframe code_javascript skills

JS dynamically adds iframe code_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 15:39:361809browse

Generally, it can be supported by IE9 and above browsers, chrome and other browsers

var iframe = document.createElement('iframe'); 
iframe.src="http://www.jb51.net";  
document.body.appendChild(iframe);

But considering browser compatibility issues, you can use the following code

try{  
   var iframe = document.createElement('<iframe name="ifr"></iframe>');  
  }catch(e){ 
    var iframe = document.createElement('iframe');  
    iframe.name = 'ifr';  
 }

or

if(ie && version < 9) {
  var iframe = document.createElement('<iframe src="http://www.jb51.net"></iframe>');
} else {
  var iframe = document.createElement('iframe');
  iframe.setAttribute('src','http://www.jb51.net');
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn