不。这是纯粹的客户端特定功能。事实上,获得只支持一个窗口的浏览器和target
属性根本无效的浏览器是完全可能的。甚至有人努力使该属性完全从未来的HTML标准中消失(例如,XHTML分支没有这样的属性)。
我能想到的HTML和HTTP之间唯一的重叠是<meta http-equiv>
标签(其中HTML会影响HTTP控制的行为)。 HTTP是一种传输协议,旨在处理任何类型的数据。让它控制呈现将是一个非常可怕的担忧组合。
幸运的是,我们生活在一个支持JavaScript的世界。使用AJAX请求验证表单相当容易,特别是对于像jQuery这样的库。
例如,该脚本对URL执行POST请求(在这种情况下,/pdf/validate
),并期望页面发回“ok”(如果一切正常)或其他情况下发生错误。
<form method="post" action="/pdf/send" id="pdf-form">
<!-- form stuff here -->
</form>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
// set to true if we are to bypass the check
// this will happen once we've confirmed the parameters are okay
var programmaticSubmit = false;
// attach an event handler for when the form is submitted
// this allows us to perform our own checks beforehand; we'll do so by
// cancelling the event the user triggered, and do the submit ourselves if
// we detect no error
$('#pdf-form').submit(function(event)
{
if (!programmaticSubmit)
{
// first off, cancel the event
event.preventDefault();
// do an AJAX request to /pdf/validate
$.ajax("/pdf/validate", {
type: "POST",
data: $(this).serialize(), // send the form data as POST data
success: function(result)
{
// this gets called if the HTTP request did not end
// abnormally (i.e. no 4xx or 5xx status);
// you may also want to specify an "error" function to
// handle such cases
if (result == "ok")
{
// since the server says the data is okay, we trigger
// the event again by ourselves, but bypassing the
// checks this time
programmaticSubmit = true;
$(this).submit();
}
else // something went wrong! somehow display the error
alert(result);
}
});
}
});
});
</script>
那就是JavaScript了。我终于找到了一个涉及[Window-Target](http.http-stats.com/Window-Target)HTTP头的文件,但文档实际上并不存在,而Firefox忽略了它......我可能会最终使用非常类似于JS的东西 - 谢谢! – 2011-03-31 00:43:43
@Xavier Holt从来没有听说过那个!必须是另一个MS特定的未公开扩展。 – zneak 2011-03-31 02:15:39
我还没有 - 我在看到你提到的那些''标签时偶然发现了它。还有另外一个信誉良好的来源提到它[这里](http://vancouver-webpages.com/META/metatags.detail.html),但他们只能说:“指定命名窗口当前页面;可用于停止出现在包含许多(不是全部)浏览器的框架中的页面。“不知道什么实际上支持(支持?)它... – 2011-03-31 03:17:50