Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

meteor

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?

like image 882
zorlak Avatar asked Dec 17 '12 07:12

zorlak


People also ask

How do I make a link open in a new window or tab?

How to Open Hyperlinks in a New Browser Tab or Window. The short answer is: just add a target="_blank" attribute to your links (anchor tags). Now when your visitors click that link, it will open in a new window or tab (depending on which web browser they are using and how they configured that browser).

How do I open a new window when I click on a link?

To create a new window or tab when a link is clicked, the target="_blank" attribute must be in the a href tag, as shown below.

Can you make the link open in a new tab JavaScript?

Open URL in New Tab using JavaScript If you want to open URl in a new tab, you have to use "_blank" in second parameter of window. open().

Is there a way to open links in a new tab without switching to that tab?

Use Keyboard with Mouse/Trackpad You can load any link in a new browser tab by clicking or tapping on it while holding down the Control key (Windows) or the Command key (Mac). Each tab loads in the background, so it's an ideal method to open multiple links as you move your way through a webpage.


1 Answers

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.

like image 71
Kyle Finley Avatar answered Nov 08 '22 11:11

Kyle Finley