0

I have a page hosted on https with iframe content that has http links within it. The framed content is on another domain but is https but I want to be able to make the http links open into a new tab. So far I have not been able to acheive this through jquery.

Example.

<html>

<head>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script>
    $(function() {
      $("a[href^='http://']:not([href*='https://'])").each(function() {
        $(this).click(function(event) {
          event.preventDefault();
          event.stopPropagation();
          window.open(this.href, '_blank');
        }).addClass('externalLink');
      });
    });
  </script>
</head>

<body>
  <div class="banner">
    <a href="http://example.com">WE ARE STILL HERE</a>
    <iframe name="home" scrolling="auto" height="100%" width="100%" noresize="true" src="https://www.example.com">
</iframe>
  </div>

</body>

</html>

You can try this with various mixed content pages. You will notice the placeholder link "WE ARE STILL HERE" opens perfectly to a new window while anything in the iframe will not load without choosing to allow insecure content.

Any help will be greatly appreciated.

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71
  • Possible duplicate of [Invoking JavaScript code in an iframe from the parent page](https://stackoverflow.com/questions/251420/invoking-javascript-code-in-an-iframe-from-the-parent-page) – Xhynk Jul 27 '18 at 00:15
  • `window.open(this.href, '_blank');` around this line, i dont see that you actually invokes https link.. it only open new tab (or window) on click for the existing link.. – Bagus Tesa Jul 27 '18 at 00:16
  • 2
    You can't access inside the iframe due to *"same origin policy"* – charlietfl Jul 27 '18 at 00:18

1 Answers1

0

If iframe url and main page url are on the same domain, well it could be done by this code to access elements which are placed inside iframe

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;

But if not actually there is not way

nimatramon
  • 11
  • 2