不。這是純粹的客戶端特定功能。事實上,獲得只支持一個窗口的瀏覽器和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