简体   繁体   中英

Capture the POST or GET data of an iframe

I have an iframe on my webpage which is on a different domain. I know for security reasons in the browser it's not possible to access the content of that iframe using javascript, but can I detect any POSTs or GETs that take place as the user navigates from page to page of the iframe?

If you own both application you can teach them to communicate with postMessage API: https://developer.mozilla.org/en-US/docs/Web/API/Window.postMessage

With not much work you can create a simple method on iframe side that will tell what is its current window.location .

If you control the server, you can pass back some vars by printing them to parent.yourMethodToHandle() with some server side code. For example:

with php on the child page(in the iframe):

 $post_var = $_POST['var'];
 echo "<script type='text/javascript'>$(function(){parent.yourMethodToHandle('$post_var')});    </script>";

and the JS on your parent page(containing the iframe):

 <script type='text/javascript'>
 function yourMethodToHandle(post_var){//Do things}
 </script>

如果是同一域,服务人员可能会帮助您捕获正在发出的请求,拦截并返回您想要的任何内容。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM