Home > Web Front-end > JS Tutorial > body text

Solution to the problem that the iframe of document.createElement in IE cannot set the attribute name_javascript skills

WBOY
Release: 2016-05-16 15:39:31
Original
2045 people have browsed it

The name of the iframe can be the target of a link or form. Open the link or form to this iframe.
I encountered an issue before where I couldn’t set the name attribute of an iframe in IE

JavaScript code

var iframe = document.createElement('iframe');  
iframe.name = 'ifr';  
//iframe.setAttribute('name', 'ifr'); //这样也不行 
Copy after login

Neither of the above two methods can be set. Later I found out that it can also be created like this

JavaScript code

var iframe = document.createElement('');

This is no problem in IE, but this method cannot be passed in Firefox. So finally

JavaScript code

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

This way it is compatible.

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