Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-05-04 15:51:07

papamoose83
New Member
Registered: 2008-05-04
Posts: 2

How do I open a new window for a link

Hi,

I need to know how to get my links to display in a new window. I’m using the form “plainlinks” to display all my links. Which is…

<txp:linkdesctitle /><br />

How do I modify this so that the links will open in a new window?

I’ve looked around on the net and came across a PR BLOCK plugin- but the download link doesn’t work.

http://thresholdstate.com/software/3740/pr-block

Thanks for looking at this!!!! I’m new to Textpattern so I need detail in how to do it!!!

Offline

#2 2008-05-04 16:04:34

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

Re: How do I open a new window for a link

This actual isn’t TXP question. You just need some Javascript that opens links to a new window.

In example you could do it like:

<a rel="external" href="<txp:link_url />" title="<txp:link_description escape="html" />"><txp:link_name /></a>

And then some JavaScript:

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") anchor.target = "_blank";
	}
}
window.onload = externalLinks;

That you can place into js-file and then call it form your page.

Last edited by Gocom (2008-05-04 16:05:29)

Offline

#3 2008-05-04 16:20:16

papamoose83
New Member
Registered: 2008-05-04
Posts: 2

Re: How do I open a new window for a link

Thanks!! That works great!

Offline

#4 2008-05-04 20:07:37

pepebe
Member
From: Mannheim, Germany
Registered: 2005-02-07
Posts: 74

Re: How do I open a new window for a link

Ich hoffe, ich habe deine Frage nicht verstanden aber ich denke, das klappt auch ohne Java Script. Zu dem Thema habe ich vor einiger Zeit mal was geschrieben. Ich hoffe das hilft dir weiter.

Quelle: http://webwohnraum.blogspot.com/ (Mein Blog, zur Zeit wegen Umbauabeiten offline)

Links in neuem Tab/Fenster öffnen

Wer möchte, daß sich Links in einem neuen Tab oder Fenster öffnen, muß den Link entsprechend gestalten. Leider ist der Editor von blogspot ein wenig knausrig. Außer dem Ziel des Verweises, nimmt er keine Informationen auf. Dabei kann man dem Link noch viele nützliche Informationen mitgeben.

Das “target” Attribut

Eine dieser Informationen ist die Anweisung an den Browser den Link in einem neuen Tab/Fenster zu öffnen. Hierfür ist das “target” attribut zuständig. Gibt man als Ziel für target “_blank” an, so bewirkt ein Klick auf den Link das öffnen eines neuen Fensters.

<a href=“URL” target=”_blank”>Linktext</a>

Bsp. help.blogger.com

Probleme?

Funktioniert das nicht, so könnte das an einer falschen doctype Definition liegen. “_blank” funktioniert nur unter “transitional”. In meinem Template war die doctype “strict”.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”<

Nachdem ich das zu “transitional geändert habe, hat es dann funktioniert.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>

Wichtig: Eine veränderte Doctype kann schwerwiegende Veränderungen auf die Darstellung eines Layouts im Browser haben. Bevor man die Doctype dauerhaft ändert, sollte man deshalb sein Layout gründlich überprüfen.

So, ich hoffe das hilft dir weiter.

Gruß,

pepebe

P.S. Wie man “target” in den Link tag integriert, hängt von der verwendeten Technik der Link erstellung ab. Ich glaube ohne ein entsprechendes Formular geht es nicht.

Offline

#5 2008-05-05 00:17:50

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

Re: How do I open a new window for a link

Isn’t this wrong forum for German? This is the main and also known as the English forum, when there is the seperate German forum too…

Offline

#6 2008-05-05 11:00:32

pepebe
Member
From: Mannheim, Germany
Registered: 2005-02-07
Posts: 74

Re: How do I open a new window for a link

German? English?

Oh my god!

Sorry, your right! I really didn’t notice the post was in english nor did I notice my reply was in german.

I apologize, really. I suppose I was a bit tired yesterday.

OK, a quick translation.

How to open a link in a new tab/window

It all comes down to use the target attribut for your link.

If you write a link like this:

<a href=“URL” target=”_blank”>Linktext</a> it will automatically open in a new window or tab.

If this diesn’t work, you have to check if you are using the necessary doctype. It has to be “transitional”.

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/x >

If your document is using strict, the magic won’t work at all.

This was the easy part.

I have checked through the references but I couldn’t find a way how to add ‘‘target=”_blank”’‘ to any of the txp linktags. That’s a sad thing, because I think this should not be a problem.

So I think it can’t be done with linkdesctitile.

I’m just trying to get a hang on txp snytax again, so the only idea that comes to my mind is some kind of txp:articel or txp:article_custom construction along with a form that builds your links. But that would only work for articles sections and categories. How to get a list of your links that are shaped like that is beyond me right now.

Greetings,

pepebe

P.S. I don’t understand why there doesn’t seem to be a way to add title to a link (link item). It feels natural for me to to give your user a choise.

Something like this “Follow Link” or “Open link in a new window” would be much more user friendly.

Offline

#7 2008-05-05 14:21:53

keith
Member
From: Blyth, Northumberland, England
Registered: 2004-12-08
Posts: 199
Website

Re: How do I open a new window for a link

pepebe wrote:

I have checked through the references but I couldn’t find a way how to add ‘‘target=”_blank”’‘ to any of the txp linktags. That’s a sad thing, because I think this should not be a problem.

This might help – I use it, and it is a perfect solution for me.


Keith
Blyth, Northumberland, England
Capture The Moment

Offline

#8 2008-05-05 15:00:25

pepebe
Member
From: Mannheim, Germany
Registered: 2005-02-07
Posts: 74

Re: How do I open a new window for a link

Ok, here is a solution that will work without any client side java script.

Download the msv_link plugin

http://textpattern.org/plugins/858/msv_link

Install and create a form for your linklist.

<txp:msv_link target=”_blank” class=“mylinkstyle” rel=“alternate” />

Now you may, among other useful things add a target to any link. Classes, IDs are also now subject to your creative mind.

Try it, it works great for me!

Greetings,

pepebe

Offline

Board footer

Powered by FluxBB