views:

402

answers:

1

Hey Guys,

This seems to be a common issue, and the solutions which I have seen do not seem to be working for me.

We've got a dynamically generated and inserted iframe, with a form which submits to it. Works fine in FF and IE8, but in 7 we are getting the iframe name issue (IE does not want to set iframe name using element.name or element.setAttribute("name",) ).

So I've converted our code over to this:

function insertTrafRepiFrame(){
    var contDiv = document.getElementById('trafficReportDiv');
    if(contDiv != null){
        var iFrame;
        try{
            iFrame = document.createElement('IFRAME');
        }catch(ex){
            iFrame = document.createElement('<iframe name="trafficreport">');                                        
        }
        iFrame.name = "trafficreport";
        iFrame.id = "trafficreport";
        iFrame.style.border = 0;
        iFrame.src = "http://www.frixo.com/widget/widget-report-area.aspx?road=all%38map=small%38latitude=51.1421%38longitude=-0.07545%38radius=50%38roadsearch=no%38roadlink=yes%38reporttype=full";
        while(contDiv.hasChildNodes()){
            contDiv.removeChild(contDiv.firstChild);
        }
        contDiv.appendChild(iFrame);
    }
}

With this form:

<form name="traffic_report" id="traffic_report" target="trafficreport" action="http://www.frixo.com/widget/widget-report.aspx" onsubmit="javascript:return CheckResponse(this);" method="get">
    <div id="trafficRepFormInps">
        <input type="hidden" name="map" value="small" />
        <input type="hidden" name="roadsearch" value="no" />
        <input type="hidden" name="roadlink" value="yes" />
        <input type="hidden" name="reporttype" value="full" /><br />
        <label for="road">Type a road below, i.e. M23:</label><br />                           
        <input name="road" value="M23" id="road" class="citysearchbox" type="text" /> 
    </div>
</form>

What I have noticed is that in developer tools, IE in 7 mode shows the iframe an attribute of submitName, where as 8 mode shows an attribute of propdescName. Could this discrepancy be causing this form misfiring? Or have I missed out on something else?

Thanks, Psy

(PS. No moans about iFrame over iframe variable name please :p )

A: 

I think you do it right with the document.createElement('<iframe name="trafficreport">');

But I'm not sure it is called as the document.createElement('IFRAME') will be ok, even in IE.

We are using a dynamic iframe to sandbox cross domain JSONP calls, and it works fine in IE. The code I use is:

var ifr = /MSIE/.test(navigator.userAgent) ? 
    document.createElement('<iframe name="'+id+'">'):
    document.createElement('iframe');
    ifr.name = id;

You can check a working example here click on the Demo link. If the demo works it means something is wrong in your code, if it doesn't work, something is wrong with your IE configuration.

Mic
The createElement('IFRAME') is not an issue, as that is the non-ie bit, and it works fine in ff using that method.
Psytronic
Sorry I don't get what is not working. For me the catch clause in your code will never be called as even in IE7 the try clause will be successful.I remember a painful time to make the example from the link above to work in IE, especially with the name attribute. May be if you put a debugger (Visual Web Express can run in remote). And you will see the steps and may be spot a difference.
Mic
Ah, sorry, yes. I misunderstood what you were trying to say. I've switched the two statements around in the try catch, and testing now.
Psytronic
Yup that works.
Psytronic