I want to disable all links inside an IFRAME, when people click on those link, alert would popup.
Here is what I have so far, but the jQuery does nothing. Not sure what I did wrong.
Thanks in advance. |
|||||
|
or else you could put the script inside the iframe itself and thus
shortening the code to this way. lighter performance i believe.
|
||||
I would expect that
$(document).ready executes before the content of the iframe has loaded. Try using the onload attribute for the iframe instead. |
|||||||||
|
This is the generic solution of your problem. Hope this will work well.
|
||||
A legend over at
http://www.webdeveloper.com/forum/showthread.php?182260-Can-we-disable-links-inside-iframes revived a technique from the good old days, back when we didn't have calls like -webkit-gradient() and men were men. Just put a transparent div over it! |
|||||||||||||
|
The solution mentioned by "lol" actually works quite well. I
stumbled on this accidentally after working on this for a couple of
hours...
Put your iframe inside a div element, then make the div transparent and push the z-index of the iframe behind the div. See this example:
Then set up your css like this:
Load up your page and the div is what will accept the click events, not the iframe. |
|||
As an alternative to preventing default you can change anchors to spans so it is more visible that link is not link anymore.
|
|||
None of the above answers will work unless maybe you are loading the
content locally because by the time the window.load event fires the
iframe hasn't typically loaded yet. You can add a listener to the iframe
to find all a's inside the iframe and disable them.
|
|||||
|
I was looking to disable
iframe links too and couldn't find a solution. Thanks to HTML5, you can easily disable links by simply adding the sandbox attribute.
view demoI hope this helps someone searching the net, especially since this questions pops up first on Google. |
|||