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

JS dynamically adds iframe code_javascript skills

WBOY
Release: 2016-05-16 15:39:36
Original
1760 people have browsed it

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);
Copy after login

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';  
 }
Copy after login

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');
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template