gztomas
gztomas

Reputation: 3260

How can I disable an anchor href with target _blank?

I have this HTML line:

<a href="<%url%>" target="_blank">link</a>

Where <%url%> is a token I have to replace with a value that produces the click to do absolutely nothing. Note the anchor is in an iframe with the top same domain.

Consider:

  1. I really do have to use an anchor
  2. I have tried with the values # and javascript:void(0) but since the target is _blank they change the top.location.href to the iframe window.location.href so the iframe is loaded as the top window
  3. I can't modify the HTML except for the token
  4. No jquery

Upvotes: 0

Views: 3603

Answers (3)

gztomas
gztomas

Reputation: 3260

I found the way:

javascript:void(this.onclick=function(){return false;})

Upvotes: 1

Michael
Michael

Reputation: 498

If you can put any string into the token, then make it end the href, then also include an onclick that cancels the click. Try replacing the token with this:

#" onclick="return false;

Upvotes: 0

Ondrej Svejdar
Ondrej Svejdar

Reputation: 22054

Can you add attribute

onclick="return false;"

?

Upvotes: 0

Related Questions