How to make link open in new tab or window in Meteor

meteor

Solution

This seems like a bug. I think Meteor should ignore links with `target="_blank"`. Maybe you could create an issue on the issue tracker

That said, I have successfully done this as a work around:

test.html

<template name="test">
  <a href="/new-window" target="_blank">Open new window</a>
</template>

test.js

Template.test.events({
  'click a[target=_blank]': function (event) {
    event.preventDefault();
    window.open(event.target.href, '_blank');
  }
});

Also, I have found that adding `http://` works for external links E.g.

<a href="http://twitter.com" target="_blank">Open new window</a>

I'm not sure why these things didn't work for you. I have only tested them in Chrome, however, so maybe this is a browser issue.

Problem

I haven't found anything that has worked. I've tried all of the following, to no avail: - added the attribute `target="_blank"` to the `<a>` - added `target="someName"` to the `<a>` - URL starts with `'/'` - URL starts with `Meteor.absoluteUrl()` - URL starts with `Meteor.absoluteUrl()` with the `"http://"` removed - URL as string literal, not returned from template helper - `<a>` inside `{{#constant}}` region in template - `<a>` not inside `{{#constant}}` region in template - `<a>` in the body outside of any template at all - `<a>` appended to the body in the browser console - `window.open([url],[target])` with all the aforementioned combinations. In all cases, the link opens in the same tab as where it was clicked, except for the URLs that didn't start with `http://`, which opened an `about:blank` page in a new tab. Any idea what's causing this, or how to solve it?

Original source

Related problems