/    Sign up×
Community /Pin to ProfileBookmark

How do I open a link in a new window?

I see this all the time and I can’t find a code for it.
Click on a link and it opens in a new window.
Example:
<a href=”http://www.adomain.com/overthere”>Click Here</a>

to post a comment
HTML

14 Comments(s)

Copy linkTweet thisAlerts:
@welshNov 28.2005 — Use:

<a href="http://www.adomain.com/overthere" target="_blank">Click Here</a>
Copy linkTweet thisAlerts:
@SheldonNov 28.2005 — or you can use javascript to open a resized window, search teh javascript forum and you will find heaps of code to do it,

Rememberin that 10% of browsers dont support javascript but more people have pop-up blockers installed.
Copy linkTweet thisAlerts:
@MstrBobNov 28.2005 — Use:

<a href="http://www.adomain.com/overthere" target="_blank">Click Here</a>[/QUOTE]


Really, avoid that target attribute if you can. It is depreciated.

[code=html]
<a href="http://www.adomain.com/overthere" onclick="window.open(this.href);return false;">Click Here</a>
[/code]


Basically, add:

onclick="window.open(this.href);return false;"

To your links.
Copy linkTweet thisAlerts:
@anothenauthorNov 28.2005 — Really, avoid that target attribute if you can. It is depreciated.

[code=html]
<a href="http://www.adomain.com/overthere" onclick="window.open(this.href);return false;">Click Here</a>
[/code]


Basically, add:

onclick="window.open(this.href);return false;"

To your links.[/QUOTE]


YAAY! it works !!

[excited]*dances around*[/excited]
Copy linkTweet thisAlerts:
@pathfinder74Nov 29.2005 — Use:

<a href="http://www.adomain.com/overthere" target="_blank">Click Here</a>[/QUOTE]


How do you validate an XHTML doc with a _
blank target? I can't figure it out for the life of me.
Copy linkTweet thisAlerts:
@CharlesNov 29.2005 — How do you validate an XHTML doc with a _blank target? I can't figure it out for the life of me.[/QUOTE]The same way you validate an HTML document with the target attribute, use the transitional DTD.
Copy linkTweet thisAlerts:
@anothenauthorNov 29.2005 — or you can use javascript to open a resized window, search teh javascript forum and you will find heaps of code to do it,

Rememberin that 10% of browsers dont support javascript but more people have pop-up blockers installed.[/QUOTE]

I usually set my pop up blocker to allow for certain sites. It can also be set to temporarily allow.

What I don't like is when there is a javascript command where I can't right click and open in new window. It forces me to allow popups.
Copy linkTweet thisAlerts:
@pathfinder74Nov 29.2005 — The same way you validate an HTML document with the target attribute, use the transitional DTD.[/QUOTE]


What if you're doing it with strict?
Copy linkTweet thisAlerts:
@CharlesNov 29.2005 — What if you're doing it with strict?[/QUOTE]Then you can't use the "target" attribute just like you can't use the FONT element.

Why on earth are you bothering with XHTML?

Use HTML 4.01 Strict and [font=monospace]<a href="http://www.w3.org/" onclick="window.open (this.href, 'child'); return false">W3C</a>[/font]
Copy linkTweet thisAlerts:
@CharlesNov 29.2005 — Really, avoid that target attribute if you can. It is depreciated.[/quote]The "target" attribute is an odd duck. It was removed from the Strict DTDs but not depricated.

http://www.w3.org/TR/html401/present/frames.html#adef-target
Copy linkTweet thisAlerts:
@MstrBobNov 29.2005 — The "target" attribute is an odd duck. It was removed from the Strict DTDs but not depricated.

http://www.w3.org/TR/html401/present/frames.html#adef-target[/QUOTE]


Ahh, you appear to be right. Well, being as how it's intended for frames, and Frames are only in the Transitional DTD, there's no need for them in the Strict. I still think that use of it to open windows is a bit of an abuse. But whichever, when it comes down to it, don't use it in strict.
Copy linkTweet thisAlerts:
@pathfinder74Nov 30.2005 — Really, avoid that target attribute if you can. It is depreciated.

[code=html]
<a href="http://www.adomain.com/overthere" onclick="window.open(this.href);return false;">Click Here</a>
[/code]


Basically, add:

onclick="window.open(this.href);return false;"

To your links.[/QUOTE]



I'll give this a try. Thanks.

I generally try not to abuse the _blank href too much. If it's a link to another site (absolute link) I'll generlly try to open it in a different window. But now I'm hearing that's not the best way to do things because people surfing your site will generally expect to be able to push the "back" button on their browser to get back to where they left off on your site. I have been doing it from the approach that I take when surfing. I find I get lost using a single browser window so I open news ones for most links I click on and almost always have my left fingers on CTRL +W waiting to get rid of it.

But I guess most "average' people don't even know how to use keyboard shortcuts to do anything.
Copy linkTweet thisAlerts:
@MstrBobNov 30.2005 — I might suggest that you find a way to personally [URL=http://browsehappy.com/]browse happy[/URL]. Seriously though, I highly recommend [URL=http://www.mozilla.com/firefox/]Firefox[/URL] and [URL=http://www.opera.com]Opera[/URL]. Tabbed browsing is a must, I really couldn't go without it.

Leave it to the user to decide wether to open a new window or not. There certainly is nothing wrong with distinguishing outgoing links from internal links. Be it including a small symbol next to links or giving them a separate color, they can be quite handy to users. Forcing a new window is not good usability practice. If I find an outgoing link I simply middle click and view it in a new tab. Otherwise, I want to keep my browsing history. Just a tip.
Copy linkTweet thisAlerts:
@stacywacyNov 30.2005 — What does CTRL +W do? Not that I plan on using it, I'm just curious. Anyway, when I'm browsing the web I prefer to have links to other websites open in a new page instead of having to break my back button, especially if I click on links on the new website.
×

Success!

Help @anothen spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...