简体   繁体   中英

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

我找到了方法:

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

Can you add attribute

onclick="return false;"

?

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM