Close a bookmarklet from inside it
I'm creating a bookmarklet that performs a function similar to Amazon's add anything to your wishlist bookmarklet (http://www.amazon.com/wishlist/get-button). I'm trying to make a cancel button, but I can't seem to get it to work.
How can I make a cancel button that will display inside the iframe of the bookmarklet, and that will close the iframe?
I've tried using:window.close from inside the iframe to do it, but that didn't work. I've also tried using parent.document.body.removeChild(parent.document.getElementById('iframe')), but I get cross domain permissions issues. Any ideas?
Wrap the iframe in an div. Put the cancel button inside the div, but outside the iframe so that the cancel button is actually in the parent page. This avoids the cross origin problem.
There are ways to work around cross origin problems, but this is by far the simplest solution to your specific problem.
You are going to have to use window.postMessage to tell a function in the parent window to close it.