IE Issue: Submitting form to an iframe using javascript

前端 未结 4 809
滥情空心
滥情空心 2020-12-07 17:44

I was trying to create an iframe element using javascript, like so:

var iframe = document.createElement(\'iframe\');
iframe.setAttribute(\'name\', \'frame_x\         


        
4条回答
  •  北海茫月
    2020-12-07 18:14

    You've hit a bug in Internet Explorer.

    You CAN NOT set the name attribute of ANY element in IE using the standard DOM Method .setAttribute('name', value);

    In IE (before version 8 running in IE8 standards mode) this method will not work to set the name attribute.

    You need to use one of the following:

    //A (any browser)
    var iframe = document.createElement('iframe');
    iframe.name = 'frame_x';
    
    //B (only in IE)
    var iframe = document.createElement('');
    
    //D (using jQuery to set the attribute on an existing element)
    $('iframe:first').attr('name','frame_x');
    

提交回复
热议问题