Open iframe links

1

How do I prevent iframe links that have the target="_blank" property and open those links in another iframe only on the same page?

Example:

Content of iframe1: <a href="http://t.co/YJdEOEu8Dz" target="_blank">MEU VIDEO</a> Content of iframe2: <span>Aqui será o link que foi clicado no iframe1<span>

    
asked by anonymous 31.03.2015 / 22:28

1 answer

1

That would be ... (but you will have to change http://www.google.com.br because it will not load inside the IFrame.) . I was able to find a Google URL that works inside the IFrame, just so you can check it out.

$("body").on("click", "a", function(e) {
  var target = $(this).attr("target");
  if (target == '_blank') {
    $("#meuIFrame").attr('src', $(this).attr("href"));
    return false;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><div><ahref="http://www.google.com/custom?q=&btnG=Search" target="_blank">Google</a>
</div>
<iframe id="meuIFrame" src="" style="width: 200px; height: 200px;"></iframe>

Just like the URL http://google.com.br does not work, any URL whose response contains the X-Frame-Options: SAMEORIGIN " will also not open inside the IFrame, unless you have how to place this HTML in the same URL source.

    
31.03.2015 / 23:45