Blocking iframe links?

C

chris.poirier

Does anyone know how I could make an iframe so that the links in the
frame page are disabled ... or if this is possible?

Any help is appreciated.
 
A

ASM

Does anyone know how I could make an iframe so that the links in the
frame page are disabled ... or if this is possible?

Any help is appreciated.

you can try to target them in a blank page ?

<iframe target="_blank"

(not tested)
 
C

Christopher J. Hahn

Does anyone know how I could make an iframe so that the links in the
frame page are disabled ... or if this is possible?

Any help is appreciated.


Assuming you have zero control over the content of the iframe, you can
cover it with an invisible div. Compatibility varies-- some browsers (I
can't remember which) have problems showing a div on top of an iframe.
In some browsers, whitespace may be considered to not be there-- get
around this by filling the invisible div with an invisible image.

Of course... then they can't click on anything in the iframe.

If the iframe is not under your control but IS on the same domain, you
can loop through its links
for( var c = 0; c < document.links.length; c++ )

And set their onClick to return false.
document.links[ c ].onclick = function () { return false; }

The problem is that anything other than links can also have an event
handler that does something similar to a link, such as:
<font class=looksLikeLink
onclick="location.href = 'somepage.html';"
 
S

Stephen Chalmers

Does anyone know how I could make an iframe so that the links in the
frame page are disabled ... or if this is possible?

Any help is appreciated.
Try this function (in the parent document). It is set to act upon the first iframe.
I cannot work if the iframe's document is from a different domain.

<SCRIPT type='text/javascript'>

function zapIframeLinks(idx)
{
var ifl;

if(window.frames && window.frames[ idx ] && window.frames[ idx ].document.links)
{
ifl=window.frames[ idx ].document.links;
for(var i=0; i<ifl.length; i++)
ifl.onclick=function () { return false; }
}

}
window.onload=function(){ zapIframeLinks( 0 ) };

</SCRIPT>
 
Z

Zif

Does anyone know how I could make an iframe so that the links in the
frame page are disabled ... or if this is possible?

Any help is appreciated.

It may be obvious, but remember that any 'blocking' based on JavaScript
will fail if/when JavaScript is disabled.
 
C

chris.poirier

thanks.

This worked almost perfectly, except for mailto: links ... but that
might be due to my WebMail Compose Firefox extension.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top