你如何发布到iframe? [英] How do you post to an iframe?

查看:186
本文介绍了你如何发布到iframe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将数据发布到iframe?

How do you post data to an iframe?

推荐答案

取决于发布数据的含义。您可以在< form /> 标记上使用HTML target =属性,因此它可能是简单如下:

Depends what you mean by "post data". You can use the HTML target="" attribute on a <form /> tag, so it could be as simple as:

<form action="do_stuff.aspx" method="post" target="my_iframe">
  <input type="submit" value="Do Stuff!" />
</form>

<!-- when the form is submitted, the server response will appear in this iframe -->
<iframe name="my_iframe" src="not_submitted_yet.aspx"></iframe>

如果不是,或者您需要更复杂的事情,请编辑您的问题以包含更多内容详细信息。

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

Internet Explorer存在一个已知错误,只有在您使用Javascript动态创建iframe等时才会出现(有一个在这里解决方法),但如果你使用普通的HTML标记,你没事。目标属性和框架名称不是一些聪明的忍者黑客;虽然它在HTML 4 Strict或XHTML 1 Strict中已被弃用(因此不会验证),但它自3.2起就成为HTML的一部分,它正式成为HTML5的一部分,并且它自Netscape 3起几乎适用于所有浏览器。

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.

我已将此行为验证为使用XHTML 1 Strict,XHTML 1 Transitional,HTML 4 Strict以及未指定DOCTYPE的quirks模式,并且它适用于所有使用Internet的情况Explorer 7.0.5730.13。我的测试用例包含两个文件,在IIS 6上使用经典ASP;它们已在此完整复制,因此您可以自行验证此行为。

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

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>Form Iframe Demo</title>
  </head>
  <body>
  <form action="do_stuff.asp" method="post" target="my_frame">
    <input type="text" name="someText" value="Some Text" />
    <input type="submit" />
  </form>
  <iframe name="my_frame" src="do_stuff.asp">
  </iframe>
  </body>
</html>

do_stuff.asp

<%@Language="JScript"%><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <title>Form Iframe Demo</title>
  </head>
  <body>
  <% if (Request.Form.Count) { %>
  You typed: <%=Request.Form("someText").Item%>
  <% } else { %>
  (not submitted)
  <% } %>
  </body>
</html>

我很想知道任何浏览器没有正确运行这些示例。

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

这篇关于你如何发布到iframe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆