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?

Answers


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.


Need Your Help

What is UseDeclareFetch postgresql odbc

postgresql odbc

I'm finally testing an older .NET app on windows 10. It runs a dozen sql selects against Postgresql 9.3 (64 bit) using 32 bit 9.03 odbc. The app runs a Select to get a bit of config data Select MyR...

How to debug COM object in Visual Studio 6.0 that is created in an ASP page?

c++ com asp-classic vc6

I have an old C++ COM component which has to stay in Visual Studio 6.0 format. I can't for the life of me figure out how to debug the code in the actual COM component.