According to the Fancybox API, I am using the following code in an iframe:
<form>
... // form fields here
<button onclick="parent.$.fancybox.close();">
<span>Save</span>
</button>
</form>
The form actually closes when 'Save' is clicked -- but the form content is not submitted. It's like the close
event is triggered before the form actually submits its content.
Without the onclick
, content is submitted, but the subsequent page opens inside the iframe -- not what I want.
Is there a way around this?
Thanks for helping.
for other readers still having trouble getting fancybox to close from an iframe, it may be an issue with iframe being from a different origin as the parent window. that was the issue i was running into. Rob W provided an excellent solution using postMessage here Uncaught TypeError: Cannot read property 'fancybox' of undefined - Google Chrome only error?
This one works perfect me:
All other things didn't work.
You can use event.preventDefault() method like this:
Then submit the page using jquery
So it will be better to make it in a function like this:
I ended up solving this by creating buttons using multiple
span
(for style purposes) and a few lines of jQuery