简体   繁体   中英

Embedding iFrame form — how to get parent URL

I have a form that other people will be embedding on their site:

<form method="post" action="http://example.com/">
    <input type="text name="name" />
    <input type="submit" />
</form>

If the user submits that form on their site (that is, it is embedded in an iframe on their site), how would I get the parentURL from the request, is that possible?

Cross site scripting security prevent this, to do it you should supply your user with script that path the parent url window to the iframe.

In the page that include the iframe:

<script>
urlVal = document.location;
</script>

In your iframe page you can access urlVal by:

parent.urlVal

Make sure the script is in an onload event or just before the closing body tag so that the elem with the ID exists

 <script> var url=document.location.href; document.getElementById("fromSite").value=url; </script> 
 <form action="#"> <label for= "firstname" id="firstname">First Name*</label> <input type='hidden' value='' name='fromSite' id="fromSite"/> <input type="text" name="firstname"> <button type="submit">Submit</button> </form> 

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