1

I am dynamically creating a link using jQuery's append... Here's the code:

tr.append('<td>' + obj.title + '<a href="http://somesite.com"><i class="fa fa-external-link wb" target="_top"></i></a></td>');

This code sites in an iframed page, so when I click on this link I need it to break out of the frame... hopefully into a new tab (if possible).

My problem is that it's not linking at all and not breaking out of the frame.

How can I get this to work?

andreas
  • 16,357
  • 12
  • 72
  • 76
  • `target="_blank"` on your link will force the link to open in a new window or Tab, You may not seen the link, because there is probably nothing to show... `` is the link text... – DIEGO CARRASCAL Sep 12 '16 at 16:26

3 Answers3

1

Your target="_top" attribute is fine, but it belongs on the anchor (<a> tag) and not the <i> tag. _top is better than parent because it breaks out of all iframes and not just the first one. If that doesn't work then there is something else preventing it and it probably won't be possible.

Robert Parham
  • 704
  • 3
  • 10
0

Try the following and see if it works:

tr.append('<td>' + obj.title + '<a href="http://somesite.com" target="_blank"><i class="fa fa-external-link wb" target="_top">Test</i></a></td>');
0

You can use target="_parent" to open the link one layer above the iframe content. If you have more layers, use target="_top" to open it in the original window.

See the HTML target attribute on w3schools or MDN:

_parent: Load the response into the HTML4 frameset parent of the current frame or HTML5 parent browsing context of the current one. If there is no parent, this option behaves the same way as _self

_top: In HTML4: Load the response into the full, original window, canceling all other frames. In HTML5: Load the response into the top-level browsing context [...]

In your case, it would be:

tr.append('<td>' + obj.title + '<a href="http://somesite.com" target="_parent"><i class="fa fa-external-link wb"></i></a></td>');

Also see this question about breaking out of an iframe.

Community
  • 1
  • 1
andreas
  • 16,357
  • 12
  • 72
  • 76
  • No, not breaking out of the iframe –  Sep 12 '16 at 16:26
  • Have you checked the markup of the actual rendered page? Is the link syntax correct? You can maybe try the link with some text instead of the font-awesome icon... – andreas Sep 12 '16 at 16:28