簡體   English   中英

iframe中的表單發布會將父級重定向到發布URL

[英]Form post in iframe is redirecting parent to post URL

我以為,如果我創建了一個隱藏的iframe並將其放在其中,然后提交了表單,它將在后台iframe中提交並且不會影響主瀏覽器框架:

http://jsfiddle.net/gt7Xq/3/

如果您懶得不能訪問鏈接(請不要怪您),這是順序發生的:

// DOM is ready
// create iframe element as child of document.body
// create form as child element of iframe
// create input type=file element as child of iframe form
// submit iframe form

但是,提交表單時會發生什么,就是將父頁面重定向到iframe表單操作屬性的POST URL。

為什么是這樣? 我想念什么? 在最新版本的Chrome和Firefox 4中,我會遇到相同的行為。

我想做的就是在一個類似Ajax的庄園中上傳文件。 不幸的是,無法使用XMLHttpRequest上傳文件。 不過,這應該是個技巧-如果您在iframe中提交上傳,則應該在后台上傳。 我正在努力實現這一目標,但是失敗了。

您是否嘗試過在表單標簽中添加目標屬性?

<form action="action.php" method="post" target="_self">

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM