Quoter
Quoter

Reputation: 4302

Open links in new window

I have this jQuery script which opens a link in a new window:

$(document).on('click', 'a.externalUrl', function () {
        window.open(this.href);
    });

And in my template I got this snippet of code:

{{#Facebook}}
  <a href="{{Facebook}}" target="_blank">Facebook</a>
{{/Facebook}}

The problem is, is that it's always opening with localhost in the url, in stead of going directly to facebook.com.

Example:

http://localhost:57391/www.facebook.com

Upvotes: 0

Views: 71

Answers (3)

Aditya
Aditya

Reputation: 4463

Use "http://{{Facebook}}" or "https://{{Facebook}}" for href attribute

Upvotes: 3

Shyju
Shyju

Reputation: 218722

You need to mention the protocol also, so that it will be behave as an absolute url.

{{#Facebook}}
  <a href="http://{{Facebook}}" target="_blank">Facebook</a>
{{/Facebook}}

Upvotes: 1

Karl-Andr&#233; Gagnon
Karl-Andr&#233; Gagnon

Reputation: 33870

Add http:// before the www. It should work.

{{#Facebook}}
    <a href="http://{{Facebook}}" target="_blank">Facebook</a>
{{/Facebook}}

Without it, there's not way the browser know if you want a folder called www or an external link.

Here some documentation about absolute and relative URL : http://www.w3.org/TR/WD-html40-970917/htmlweb.html

Upvotes: 1

Related Questions