How do you post to an iframe?

前端 未结 4 2209
慢半拍i
慢半拍i 2020-11-22 00:55

How do you post data to an iframe?

4条回答
  •  眼角桃花
    2020-11-22 01:31

    Depends what you mean by "post data". You can use the HTML target="" attribute on a

    tag, so it could be as simple as:

    
      
    
    
    
    
    

    If that's not it, or you're after something more complex, please edit your question to include more detail.

    There is a known bug with Internet Explorer that only occurs when you're dynamically creating your iframes, etc. using Javascript (there's a work-around here), but if you're using ordinary HTML markup, you're fine. The target attribute and frame names isn't some clever ninja hack; although it was deprecated (and therefore won't validate) in HTML 4 Strict or XHTML 1 Strict, it's been part of HTML since 3.2, it's formally part of HTML5, and it works in just about every browser since Netscape 3.

    I have verified this behaviour as working with XHTML 1 Strict, XHTML 1 Transitional, HTML 4 Strict and in "quirks mode" with no DOCTYPE specified, and it works in all cases using Internet Explorer 7.0.5730.13. My test case consist of two files, using classic ASP on IIS 6; they're reproduced here in full so you can verify this behaviour for yourself.

    default.asp

    
    
    
      
        Form Iframe Demo
      
      
      

    do_stuff.asp

    <%@Language="JScript"%>
    
    
      
        Form Iframe Demo
      
      
      <% if (Request.Form.Count) { %>
      You typed: <%=Request.Form("someText").Item%>
      <% } else { %>
      (not submitted)
      <% } %>
      
    
    

    I would be very interested to hear of any browser that doesn't run these examples correctly.

提交回复
热议问题