admin管理员组

文章数量:1221396

I have been trying to have a small login widget that I embed within a static page inside an iframe allow someone to log into my site. The problem I get is that when the form posts it ends up appearing inside the iframe instead of as a full browser page.

I know it is possible to do this because / employs the same strategy on their home page. They embed an iframe inside their static page that does all their logic for them. I have very similar javascript in that I call form.submit() when someone clicks. The only difference is that I use jQuery to catch the click event vs putting the onclick directly on the form element.

I have looked at their code in their calm.js and it seems to be doing a simple form.submit() as I do, but their page loads fully in the browser vs only in the iframe. I have looked around SO and not seen a similar post, so if I just missed it, please let me know.

I have been trying to have a small login widget that I embed within a static page inside an iframe allow someone to log into my site. The problem I get is that when the form posts it ends up appearing inside the iframe instead of as a full browser page.

I know it is possible to do this because https://www.salliemae.com/ employs the same strategy on their home page. They embed an iframe inside their static page that does all their logic for them. I have very similar javascript in that I call form.submit() when someone clicks. The only difference is that I use jQuery to catch the click event vs putting the onclick directly on the form element.

I have looked at their code in their calm.js and it seems to be doing a simple form.submit() as I do, but their page loads fully in the browser vs only in the iframe. I have looked around SO and not seen a similar post, so if I just missed it, please let me know.

Share Improve this question asked Jan 25, 2012 at 22:14 ScottScott 17k16 gold badges82 silver badges122 bronze badges 2
  • If the request crosses domains, ports or protocols, browsers shoot it down. Google XSS for more information. – Blender Commented Jan 25, 2012 at 22:18
  • in my case (and the salliemae example above) they are both on the same domain. So for the question, how do I do it assuming both are on the same domain? Salliemae only has the lower level domain in common, they are on different subdomains (www. vs. login.) – Scott Commented Jan 25, 2012 at 22:20
Add a comment  | 

2 Answers 2

Reset to default 16

See target="_top" in the iframe's <form> tag. That tells the browser to load the response in the parent frame.

If you do not ajax the content, you just add target="_top" to the form, otherwise you will have to use window.open(*serialisedurl*,"_top")

本文标签: javascriptHow to submit a form from inside an iframe and have result be outsideStack Overflow