Home >Web Front-end >JS Tutorial >Solution to the problem that the iframe of document.createElement in IE cannot set the attribute name_javascript skills
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'); //这样也不行
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('2049015ba9c73891d46baf35dd342298065276f04003e4622c4fe6b64f465b88');
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'; }
This way it is compatible.