-2

I'm working on a bookmarklet which is actually an iframe injected to the DOM by clicking the bookmarklet. So, is there any method to remove this iframe from the DOM (actually close this bookmarklet) when clicking like a cancel button in the html page the iframe loaded? Just like Delicious bookmarklet did. I hope you guys can understand what I mean, Thank you!

zhiyuanL
  • 11
  • 2
  • 1
    possible duplicate of [JavaScript DOM remove element](http://stackoverflow.com/questions/8830839/javascript-dom-remove-element) – CalebB Mar 27 '15 at 13:39
  • A little research goes a long way. [JavaScript DOM remove element](http://stackoverflow.com/questions/8830839/javascript-dom-remove-element) was the first result in my search and most likely your solution. – CalebB Mar 27 '15 at 13:42

1 Answers1

0

Wether it's possible or not depends on the CORS rules.

When you're allowed to do it according to these rules, you can use the window.frameElement object.

That's as simple as that:

Page containing iframe:

<iframe src="somepage.html"></iframe>

somepage.html

<input
    type="button"
    value="Click me!"
    onclick="window.frameElement.parentNode.removeChild(window.frameElement)"
/>
Sebastien C.
  • 4,649
  • 1
  • 21
  • 32