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.
|
|
|
|
|
![]() |
||
Open in a New Browser Window
|
||
| Notices |
![]() |
|
|
LinkBack | Thread Tools |
|
|||
|
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. |
|
|
|
|||
|
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)
|
|
||||
|
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)
|
|
|||
|
Re: Open in a New Browser Window
Quote:
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. |
|
||||
|
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)
|
|
|||
|
Re: Open in a New Browser Window
Quote:
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. |
|
||||
|
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)
|
|
|||
|
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. |
|
|||
|
Re: Open in a New Browser Window
Quote:
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)
|
|
|||
|
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. |
|
|||
|
Re: Open in a New Browser Window
Quote:
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. |
|
||||
|
Re: Open in a New Browser Window
Thread Closed.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
|
![]() |
| Thread Tools | |
|
|
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 |