开发者

Knowing the status of a form POST that is protected by X-Frame-Options

开发者 https://www.devze.com 2023-03-14 05:56 出处:网络
I am going to describe my specific case below, but this might be useful to a number of web-mashups. My web application POSTs to Twitter by filling a form and then submitting it (via javascript). The

I am going to describe my specific case below, but this might be useful to a number of web-mashups.

My web application POSTs to Twitter by filling a form and then submitting it (via javascript). The target of the form is set to an iframe which has an onload trigger. When the onload trigger is called the application knows that the POST was completed.

This used to work fine until Chrome version 11, which now respects the X-Frame-Options=SAMEORIGIN sent by Twitter in the POST response. The POST goes through, but the iframe's onload is not called anymore.

It still works in Firefox 4, but I suppose that's a bug that will eventually get fixed.

Is there any 开发者_StackOverflow社区other way to know the status of the POST? I understand that knowing the contents of the POST response would violate the security policy, but I am not interested in the contents. I would just like the app to be notified when the POST is completed.


If you just need to know when the POST was submitted, and not necessarily whether it succeeded or not, you could poll the iframe's contentWindow and contentWindow.document on an interval. When you can no longer access one of those objects, or when the document has an empty body, that means that the iframe has loaded a page with X-Frame-Options restrictions, which likely means that the submission went through. It's hacky, but it looks like it will work for this purpose. (You'll probably have to go through a few combinations to figure out what the contents of restricted iframes look like in your target browsers.)


You can do it by getting the headers of the page. In php it will be looks like,

$url = 'http://www.google.com';
print_r(get_headers($url));

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号