Open in a New Browser Window

This is a discussion on "Open in a New Browser Window" within the Web Page Design section. This forum, and the thread "Open in a New Browser Window are both part of the Design Your Website category.



Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 3rd, 2008, 18:34
New Member
Join Date: Feb 2008
Location: Staffs. - UK
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Open in a New Browser Window

To open a link in a new browser window I am using target/blank.
What is the right way?
Can anyone point me to a good tutorial on this?

Many thanks.

  #2 (permalink)  
Old Feb 3rd, 2008, 18:38
Ed Ed is offline
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 687
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

There is no right way! If a user wants to open a link in a New Window, they will do it themselves.

Most users hate to be forced upon a new browser window.

Ed.
Last Blog Entry: Happy New Year! (Dec 31st, 2007)
  #3 (permalink)  
Old Feb 3rd, 2008, 18:48
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Open in a New Browser Window

No that is not the right way. The target attribute is deprecated.
The only proper way is to use JavaScript but some people disable it.
Either way i agree with Ed, if I want to open a new window I shall!
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #4 (permalink)  
Old Feb 3rd, 2008, 19:30
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

Quote:
Originally Posted by alexgeek View Post
No that is not the right way. The target attribute is deprecated.
The only proper way is to use JavaScript but some people disable it.
Don't be daft.

When you use javascript to set target="blank", you are creating invalid HTML. It doesn't matter that the validator misses it; what matters is the code served to the browser.

Just don't do it. It was deprecated for a reason.

Last edited by MikeHopley; Feb 3rd, 2008 at 19:32.
  #5 (permalink)  
Old Feb 3rd, 2008, 19:33
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Open in a New Browser Window

Not what I was suggesting Mike. I was talking about creating windows with JavaScript and setting the windows location.. not adding an target attribute.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #6 (permalink)  
Old Feb 3rd, 2008, 19:40
SuperMember

SuperMember
Join Date: May 2007
Location: UK
Age: 27
Posts: 1,111
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

Quote:
Originally Posted by alexgeek View Post
Not what I was suggesting Mike. I was talking about creating windows with JavaScript and setting the windows location.. not adding an target attribute.
Oh, those.

Well, at least that's not invalid HTML. It's still a bad solution though, especially given that many browsers block JS pop-ups.

You can do much the same thing inside the page with absolute positioning, and perhaps a sprinkling of DOM scripting.
  #7 (permalink)  
Old Feb 3rd, 2008, 19:42
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Open in a New Browser Window

Yeah that's a better solution and it can look pretty cool
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #8 (permalink)  
Old Feb 10th, 2008, 18:55
Junior Member
Join Date: Jul 2007
Location: Los Angeles
Age: 31
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

You can use the following JS function to mimic the target attribute. On your links you would use:

rel="external" instead of "target=_blank"

===================================

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;

===================================

Note: If you have other "onload" elements within your body tag you'll need to move the call in the function to within the body tag.

Last edited by imagn; Feb 10th, 2008 at 20:03.
  #9 (permalink)  
Old Feb 10th, 2008, 20:03
Ed Ed is offline
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 687
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

Quote:
Originally Posted by imagn View Post
You can use the following JS function to mimic the target attribute. On your links you would use:

rel="external" instead of "target=_blank"

===================================

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;

===================================

Note: If you have other "onload" elements within your body tag you'll need to move the call in the function to within the body tag.
We know that! It mimics something that isn't valid. Why on Earth would you want to do that? You might as well just use the target attribute, because all this does is do the same thing without the Validator noticing.

At WebForumz, we try to improve on standards, and follow the guidelines set by W3C, not find loopholes so we can exploit them!

Ed.
Last Blog Entry: Happy New Year! (Dec 31st, 2007)
  #10 (permalink)  
Old Feb 10th, 2008, 20:07
Junior Member
Join Date: Jul 2007
Location: Los Angeles
Age: 31
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

You're right the TARGET attribute isn't valid, but REL validates as strict.

Here's example article number one:

http://www.sitepoint.com/article/sta...pliant-world/3

Let me know if you'd like to me list the dozen or so other references I have on the subject.

Last edited by alexgeek; Feb 10th, 2008 at 21:36.
  #11 (permalink)  
Old Feb 10th, 2008, 20:17
Ed Ed is offline
Highly Reputable Member
Join Date: Jul 2007
Location: Cork, Ireland
Posts: 687
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Open in a New Browser Window

Quote:
Originally Posted by imagn View Post
You're right the TARGET attribute isn't valid, but REL validates as strict. Maybe at WebForumz you should do some research before chastising the people that take time out of their day to assist other members.

Here's example article number one:

http://www.sitepoint.com/article/sta...pliant-world/3

Let me know if you'd like to me list the dozen or so other references I have on the subject.
Unfortunately, that is what we call a loophole. W3C intended it so that there would be no 'Pop Ups', this is just another way of 'cheating', no matter what an article says.

Pop Ups, in any way, shape or form are bad practice. Full Stop.

Ed.
Last Blog Entry: Happy New Year! (Dec 31st, 2007)

Last edited by alexgeek; Feb 10th, 2008 at 21:36.
  #12 (permalink)  
Old Feb 10th, 2008, 21:35
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: Open in a New Browser Window

Thread Closed.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Change open in new window to open in same window nsr500rossi JavaScript Forum 2 Jan 18th, 2008 14:13
[SOLVED] open new window from main window AdRock Other Programming Languages 1 Nov 1st, 2007 02:45
open new browser window snappy Web Page Design 4 Nov 3rd, 2006 17:49
Open Browser Window Galaxyblue Web Page Design 11 Feb 14th, 2004 18:37


All times are GMT. The time now is 09:04.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43