13

I came across this question, which although somewhat low quality, demonstrated a weird behaviour with StackSnippets:

<a href="https://example.com/" target="_blank">Test (broken)</a><br>
<a href="https://example.com/">Test without target="blank" (works)</a>

target="_blank" stops the link from working. I'm running Google Chrome 50.0.2661.102 on Mac OS X 10.11. I have the same issue on Safari 9.1.11 as well.

1
  • 5
    The link is neutered without an error. This looks a lot like a sandboxing / security feature to prevent malicious users from attempting fishing through new browser windows. Commented Jun 6, 2016 at 15:03

2 Answers 2

32

Stack Snippets are run inside a sandboxed iframe which only allows modals and scripts, and does not allow access to the top navigation. So anything but _self on a link will not work because it cannot open the link that way.

Unless you have a very good reason to allow opening links in other ways via the snippets, it should remain sandboxed this way. I can't imagine many scenarios where a link actually taking you somewhere from the snippet itself would be useful. They exist to demonstrate a problem, and following links to other places doesn't really help demonstrate any problems.

2
  • 8
    "I can't imagine many scenarios where a link actually taking you somewhere from the snippet itself would be useful." well, any questions about target="_blank" or their appropriate use, such as on <a> and <form> elements, or any calls to window.open in JavaScript. I've seen plenty of questions that would have benefitted from a working example. That said, I don't think they're common enough to warrant changing the sandboxing. There are other ways of showing those particular demos in action.
    – zzzzBov
    Commented Jun 6, 2016 at 15:49
  • Of course you can't imagine it
    – Ryan
    Commented Jun 7, 2016 at 17:57
-3

StackOverflow snippets are not actually breaking your links. Snippets are iframes loading within a parent stackoverflow page. So by default you will not be able to create a new parent tab by clicking on a link from an iframe.

However you will be able to change this behaviour on your webpage. If you are trying to click on a link within an iframe and still be able to create a new blank window, then do this:

First add this to the of your parent page:

<base target="_blank" />

You can then just add an anchor with target=_blank and it will open in a new blank tab when you click on it. Voila!

2

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .