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

查看:30
本文介绍了你如何发布到 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 的怪癖模式",并且它适用于使用 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天全站免登陆