22 replies [Last post]
nicomen
Offline
newbie
Northern California
Last seen: 15 years 25 weeks ago
Northern California
Timezone: GMT-8
Joined: 2004-05-18
Posts: 10
Points: 0

How does one make a link spawn an additional browser page?

Thanks!

nicomen

velo
velo's picture
Offline
Enthusiast
Fayettenam
Last seen: 10 years 33 weeks ago
Fayettenam
Timezone: GMT-5
Joined: 2004-11-11
Posts: 181
Points: 0

This is one even I can answer.....

<a href="http://www.url.com" target="_blank">

Give a man a fire and he will be warm for a while. Set a man on fire and he will be warm for the rest of his life.

nicomen
Offline
newbie
Northern California
Last seen: 15 years 25 weeks ago
Northern California
Timezone: GMT-8
Joined: 2004-05-18
Posts: 10
Points: 0

Easy Question

Awesome! Thanks Velo!

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 12 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

Easy Question

Keep inmind, however, this won't validate using the Xhtml doctype.

Verschwindende wrote:
  • CSS doesn't make pies

thatsgame1
thatsgame1's picture
Offline
Enthusiast
Tallahassee, FL
Last seen: 11 years 45 weeks ago
Tallahassee, FL
Joined: 2004-11-06
Posts: 69
Points: 0

Easy Question

thepineapplehead - What code would be valid?

Thank you.

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 12 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

Easy Question

Now that is a subject that's caused a lot of debate. THere is no definite answer; I think there was a discussion here a little while ago.

Verschwindende wrote:
  • CSS doesn't make pies

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 44 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Easy Question

Yes there was a discussion on the subject a while ago.
In a nutshell if your using xhtml then you will find the attribute has been deprecated . This is due to the fact that it is considered a browser function controllable by the user and isn't a part of the coding of a web page and XHTML has just made the decision to clear it out .

Hugo.

P.S Have a search for the other discussion on the subject it was more detailed.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 12 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

Easy Question

However, I'm pretty sure it will validate in Xhtml transitional, just not strict.

Verschwindende wrote:
  • CSS doesn't make pies

Hugo
Hugo's picture
Offline
Moderator
London
Last seen: 4 years 44 weeks ago
London
Joined: 2004-06-06
Posts: 15668
Points: 2806

Easy Question

Your right PH, it will validate to a transitional xhtml dtd , but the issue is more to do with the ethics of the continued use of the attribute and the reasons it has been deprecated .
At the end of the day it's your choice to use it or not but it's worth bearing in mind the arguments against it's continued use and that a large body of professional opinion does seem to agree that's its use is wrong, and at an end?
Use it but use it carefully and not on every link as it does tick people off when windows keep spawning all over their screen also bear in mind your one pop up window might be the one that drains the final drop of resources from their box.

Hugo.

Before you make your first post it is vital that you READ THE POSTING GUIDELINES!
----------------------------------------------------------------
Please post ALL your code - both CSS & HTML - in [code] tags
Please validate and ensure you have included a full Doctype before posting.
Why validate? Read Me

nicomen
Offline
newbie
Northern California
Last seen: 15 years 25 weeks ago
Northern California
Timezone: GMT-8
Joined: 2004-05-18
Posts: 10
Points: 0

Easy Question

I appreciate all of your responses as it gives me more to consider while using this attribute. I am only using if for one link on my site since it is a .pdf of a poster announcing the performance of a band.

I too feel it's quite annoying to have links spawining separate windows....

Again, thank you all for your input, I truly appreciate it.

nicomen D

thepineapplehead
thepineapplehead's picture
Offline
Guru
Last seen: 1 year 12 weeks ago
Timezone: GMT+1
Joined: 2004-06-30
Posts: 9668
Points: 801

Easy Question

If you want to please everybody, then make sure you have

<a href="link" target="_blank" alt="Link (Opens in New Window)"> Link Text (opens in new window) </a>

Verschwindende wrote:
  • CSS doesn't make pies

Mælstrøm
Offline
Regular
Germany
Last seen: 12 years 30 weeks ago
Germany
Timezone: GMT-1
Joined: 2005-01-02
Posts: 46
Points: 0

Not _blank!!

I found out that _blank will not work with some browsers, even firefox. It seems to be an IE/NS old-style thing.

The command that always parsed even in strict code was

target="new"

That will work! Smile

- How many Sith does it take to screw in a light bulb?
- Only two a master, and an apprentice!

nicomen
Offline
newbie
Northern California
Last seen: 15 years 25 weeks ago
Northern California
Timezone: GMT-8
Joined: 2004-05-18
Posts: 10
Points: 0

Easy Question

I didn't know that....thanks!

nicomen D

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 13 hours 39 min ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9743
Points: 3822

Easy Question

Like most items that are deprecated for some reason, there exists a method that the item was deprecated in favor of. As in PERL, there's always a different way to do something. In the case of the target attribute, it was deprecated in favor of dhtml—in other words, client side scripting.

The important thing to remember about using script functions is that they should fail gracefully. That's not always so easy. In this case, it is.

<script type="text/javascript">
//<![CDATA[

function openlink(which) {
   window.open(which);
   return false;
   }

//]]>
</script>

<a href="http://www.somesite.com/" 
   onclick="return openlink('http://somesite.com/');">Somesite Inc.</a>

The //<![CDATA[ stuff is only needed if you're using an xhtml DTD.

When the link is clicked, the onclick event handler asks for the return value of openlink(). If the function opens a window, it returns 'false' which tells the browser not to open the href link.

If javascript is not used in the browser, or if, for example, you use vbscript and the browser is not IE, the onclick event is ignored and the browser opens href in a normal manner. The script fails gracefully.

And that's probably more than you wanted to know.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Mælstrøm
Offline
Regular
Germany
Last seen: 12 years 30 weeks ago
Germany
Timezone: GMT-1
Joined: 2005-01-02
Posts: 46
Points: 0

Welcome

You're welcome, nicomen.

Hi again, Gary. Question: Why shoot with cannons when mice are your target? Laughing out loud the target="new" command will work even in xhtml 1.1 strict, and works with every browser I have tried so far (IE5, 5+, Firefox, NS 4+, Opera). Granted, there are more out there, but those are really among those most used, and Firefox is the best of'em anyway Wink

I usually tend to not use javascript when the effect can be achieved without it, as js can be shut off, and shut off for reason Wink I don't like it and use it only when absolutely necessary Wink

- How many Sith does it take to screw in a light bulb?
- Only two a master, and an apprentice!

klaus
Offline
Enthusiast
Last seen: 14 years 50 weeks ago
Joined: 2004-11-28
Posts: 67
Points: 0

Easy Question

To my knowledge target is not supported by xhtml 1.0 strict - regardless of the value is new or _blank

The below alone works and validates:

<a href="http://www.csscreator.com" onclick="window.open(this.href,'newwin'); return false;">CSS Forum</a>

or you can try:
http://www.sitepoint.com/article/standards-compliant-world/3

Cheers
Klaus

gary.turner
gary.turner's picture
Offline
Moderator
Dallas
Last seen: 13 hours 39 min ago
Dallas
Timezone: GMT-6
Joined: 2004-06-25
Posts: 9743
Points: 3822

Re: Welcome

Mælstrøm wrote:
<snip>

Hi again, Gary. Question: Why shoot with cannons when mice are your target? Laughing out loud the target="new" command will work even in xhtml 1.1 strict, and works with every browser I have tried so far (IE5, 5+, Firefox, NS 4+, Opera). Granted, there are more out there, but those are really among those most used, and Firefox is the best of'em anyway Wink
The question is "why would you create a new document using a deprecated attribute; one that you know will be dropped at some point?"

Again, picking up paper and pen, Mælstrøm wrote:
I usually tend to not use javascript when the effect can be achieved without it, as js can be shut off, and shut off for reason Wink I don't like it and use it only when absolutely necessary Wink
This is true. Javascript should never be used for basic functionality unless, as I wrote, it is written to fail gracefully. My rather elementary code was written with clarity in mind. Klaus's one-liner is much improved over mine. Neither are cannons, but are appropriate technology for the chosen DTD.

cheers,

gary

If your web page is as clever as you can make it, it's probably too clever for you to debug or maintain.

Mælstrøm
Offline
Regular
Germany
Last seen: 12 years 30 weeks ago
Germany
Timezone: GMT-1
Joined: 2005-01-02
Posts: 46
Points: 0

Yeah

True. Too sad about the target, but the onClick event handler should work even when js is switched off Wink

Klaus: as I said, it renders well in the validator... and I never read anywhere that it is forbidden. It may be deprecated, but it is accepted.

But your code truly is the best concurrent way to handle it! Smile

- How many Sith does it take to screw in a light bulb?
- Only two a master, and an apprentice!

velo
velo's picture
Offline
Enthusiast
Fayettenam
Last seen: 10 years 33 weeks ago
Fayettenam
Timezone: GMT-5
Joined: 2004-11-11
Posts: 181
Points: 0

Easy Question

klaus wrote:

The below alone works and validates:

<a href="http://www.csscreator.com" onclick="window.open(this.href,'newwin'); return false;">CSS Forum</a>

s

Yes, but window.open() is blocked by many pop-up blockers that specifically look for that function. I stopped using that some time ago as it highly likely that a large number of users would never see the content you want them to see in the new window. While the target attribute may be deprecated, it still works and until something better comes along is still the best way (disclaimer- that I know of) to handle opening content in a new window.

Of course, part of the problem is that the "new window" option has been way overused. I hate it when content opens in a new window and I agree that it should be used sparingly and only when it's really called for. Much can be done by putting content in a hidden layer and showing it with an onClick event or similar.

Give a man a fire and he will be warm for a while. Set a man on fire and he will be warm for the rest of his life.

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 2 years 27 weeks ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

Easy Question

One of the more common use of popup windows it for images from a thumbnail gallery, or product images from a database, or some other situation where you want the user to be able to stay on the page with the links without having to navigate forwards and backwards, loading and reloading, and view the selected popup. When I use a popup in this way, it is usually "chromeless" with none of the menu, toolbars and other stuff, sized just large enough to display the content. This often enhances the presentation of an image and with all the extensions and toolbars I have at the top of FF, it gives a heck of a lot more room! There are a number of good, configurable JS scripts that do this and you always call the script in the form <a href="http://myhref.html" onclick="mypopup(this.href, 'My Popup',param1,param2...)"> where the parameters control window sizing, etc., and it will simply load in the same window if JS is turned off. Well designed popup scripts also reuse the popped up window, resize it as required, and bring it to the foreground so the multiple window and alt-tab hunt for the popup situation with some scripts are not a problem.

One of the greatest abuses of popups was in their being attached to the body onload event handler so that you would get multiple windows spawned when you visited a site that was so configured. I think we have thrown the baby out with the bathwater in the condemnation of popups, though. Like many techniques, it can be a problem if used incorrectly or improperly.

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS

florent
florent's picture
Offline
Enthusiast
Paris, France
Last seen: 12 years 50 weeks ago
Paris, France
Timezone: GMT+1
Joined: 2003-04-19
Posts: 96
Points: 0

Easy Question

velo wrote:
Yes, but window.open() is blocked by many pop-up blockers that specifically look for that function.

I don't think this is correct. My Firefox 1.0 blocks pop-ups that open as a page loads (event onLoad), but doesn't block the ones opened by a click of the mouse. Which is pretty logical since "onClick" requires user "approval" (user approves the opening of the popup - in a perfect world he should be informed that his click will open a pop-up), whereas "onLoad" doesn't imply any form of approval. All the annoying pop-ups are usually the "onLoad" type (unless several pop-ups open with one click !).

I'm a perfectionist
and perfect is a skinned knee

velo
velo's picture
Offline
Enthusiast
Fayettenam
Last seen: 10 years 33 weeks ago
Fayettenam
Timezone: GMT-5
Joined: 2004-11-11
Posts: 181
Points: 0

Easy Question

DCElliott wrote:
One of the more common use of popup windows it for images from a thumbnail gallery, or product images from a database, or some other situation where you want the user to be able to stay on the page with the links without having to navigate forwards and backwards, loading and reloading, and view the selected popup. When I use a popup in this way, it is usually "chromeless" with none of the menu, toolbars and other stuff, sized just large enough to display the content. This often enhances the presentation of an image and with all the extensions and toolbars I have at the top of FF, it gives a heck of a lot more room!

Indeed, this is true but personally I think using a hidden layer is an even slicker approach to showing the large image when a thumbnail is clicked. This was actually the reason I started learning DHTML was to learn how to do this. Now I want to know it all. ;o) This was my first DHTML project- Picture Gallery

Give a man a fire and he will be warm for a while. Set a man on fire and he will be warm for the rest of his life.

DCElliott
DCElliott's picture
Offline
Leader
Halifax, Canada
Last seen: 2 years 27 weeks ago
Halifax, Canada
Timezone: GMT-3
Joined: 2004-03-22
Posts: 828
Points: 0

Easy Question

While I agree that is a slick approach, you end up covering the thumbnails with every picture. Rather than having a page of thumnails, try setting them up in a "filmstrip" with the image below or above like: http://www3.ns.sympatico.ca/d.elliott/yum/viewerloader.html (note:only the first few thumbnails load images)(And for those of you who don't recognize the pictures, they are covers from David Weber's hugely popular Honor Harrington space opera series.)

DE

David Elliott

Before you ask
LearnXHTML|CSS
ValidateHTML|CSS