Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2009-12-14 11:47:39

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

only now it opens menu links also in new window :)

ok, basically it’s clear now

Offline

#14 2009-12-15 14:41:59

kvnmcwebn
Member
From: Ireland
Registered: 2007-01-27
Posts: 724
Website

Re: how do I display one link from a link id entered in custom field?

thanks adi. The quiet attribute in the beta version is very nice.


its a bad hen that wont scratch itself.
photogallery

Offline

#15 2010-02-04 11:54:54

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

Gocom wrote:

But if you still want to do it, you can do it with couple lines of JavaScript. Instructions are mentioned in the adi_link’s docs (ext_link="1" to the tag) and couple lines of JS.
With jQuery library syntax managing the code is real easy:

bc. $(‘a[rel=“external”]’).each(function() { $(this).attr(‘target’, ‘_blank’);
});

ok, i’m using now jQuery in this page but links still don’t open in blank page

Offline

#16 2010-02-05 11:36:27

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

tried this:

$('a[@rel$='external']').click(function(){
     this.target = "_blank";
});

and this:

$("a[href^='http://']").attr("target","_blank");

as welll, but neither did help.
what could be wrong in this page? doctype?
i’m trying to open those external links in new window

Last edited by Gallex (2010-02-05 11:54:23)

Offline

#17 2010-02-05 12:54:20

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: how do I display one link from a link id entered in custom field?

You have to wrap that code with jQuery .ready() method:

$(document).ready(function() {
    $('a[@rel$='external']').click(function(){
         this.target = "_blank";
    });
});

Or this:

$(document).ready(function() {
   $("a[href^='http://']").attr("target","_blank");
});

Tutorials:Introducing $(document).ready()


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#18 2010-02-05 13:23:56

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

but still links not opening in new window :(

Offline

#19 2010-02-05 14:18:18

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: how do I display one link from a link id entered in custom field?

Gallex wrote:

but still links not opening in new window :(

Invalid Javascript, that’s why. It won’t work:

  1. Quotes are wrong. ‘I’ am ‘variable’.
  2. Wasn’t @ removed…?
  3. Okay.

Suggestions:

  1. Use an editor that colors/highlights your code (like textedit, notepad++). Makes your life so much easier.
  2. Search. If you did search google, first hit provided correct answer to this case. But that’s just my alternate reality.
  3. 1 2

Sometimes learning is better than just ask and abe. It gives you more and eventually you notice that you have so much to give and share to others — or buff-up.

Offline

#20 2010-02-06 10:13:18

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

Gocom wrote:

Invalid Javascript, that’s why. It won’t work:

  1. Quotes are wrong. ‘I’ am ‘variable’.
  2. Wasn’t @ removed…?
    Suggestions:
  3. Use an editor that colors/highlights your code (like textedit, notepad++). Makes your life so much easier.

downloaded, installed notepad++
it tells me nothing wrong with that code

$(document).ready(function() {
$('a[rel="external"]').each(function() {
	$(this).attr('target', '_blank');
});
});

or that

$(document).ready(function() {
    $('a[@rel$='external']').click(function(){
         this.target = "_blank";
    });
});

or that

$(document).ready(function() {
   $("a[href^='http://']").attr("target","_blank");
});

Search. If you did search google, first hit provided correct answer to this case. But that’s just my alternate reality.

i did. first code i get from here ,can’t find second one right now…
copy-pasted them to template, re-typed quotes, double-checked the code…nothing

Offline

#21 2010-02-06 14:45:12

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: how do I display one link from a link id entered in custom field?

Gallex wrote:

downloaded, installed notepad++
it tells me nothing wrong with that code

It’s an editor not a miracle-validator. It doesn’t validate your code, it highlights your syntax. That’s what most syntax editors do:

You can clearly see that something is wrong with that code.

Offline

#22 2010-02-06 15:00:58

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

no, i can’t. everywhere is pair of quotes. where’s the trick?

Last edited by Gallex (2010-02-06 15:13:46)

Offline

#23 2010-02-06 16:38:22

maniar
Member
From: Hamilton, Ontario
Registered: 2010-01-04
Posts: 66
Website

Re: how do I display one link from a link id entered in custom field?

@Gallex – Yes there is something wrong in line 1 and line 3.

You cannot have a single quote within a single quote or a double quote within a double quote.

You need to alternate them for example:

$('a[rel="external"]').
$("a[rel='external']").

اردو میں بھی دستیاب Textpattern آپ کے لیے اب

Offline

#24 2010-02-07 08:37:25

Gallex
Member
Registered: 2006-10-08
Posts: 1,315

Re: how do I display one link from a link id entered in custom field?

is it correct code now?

$(document).ready(function() {
    $('a[@rel$="external"]').click(function(){
         this.target = "_blank";
    });
});

Offline

Board footer

Powered by FluxBB