SitePoint Sponsor |
|
User Tag List
Results 1 to 19 of 19
-
Jan 7, 2008, 10:30 #1
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
toggle between two browser tabs or windows
Before switching to XHTML I used the following script to enable website viewers to have two windows open and toggle between them:
Code:<script type="text/javascript"> <!-- var newWindow = null; function makeNewWindow(href, preview) { if (newWindow && !newWindow.closed) newWindow.focus(); else newWindow = open(href, preview); return false; } -->
HTML Code:<h3>When you click <a href="/home/<?php echo $site_address;?>" target="preview" onclick="return makeNewWindow(this.href,this.target)">here</a> you will open a new tab where you will see....</h3>
-
Jan 7, 2008, 10:33 #2
- Join Date
- Jan 2005
- Location
- Too far up north
- Posts
- 1,566
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Any special reason that you switched to XHTML?
The target attribute is not supported in XHTML, you will have to use JavaScript to achieve this.
-
Jan 7, 2008, 10:57 #3
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I switched to XHTML for many reasons, but that's another story. What I'm asking for is suggestions for changing the above script so that it will validate in XHTML.
-
Jan 7, 2008, 11:23 #4
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The target attribute is deprecated in HTML 4.01 Strict, in XHTML 1.0 Strict and in XHTML 1.1.
It is allowed in HTML 4.01 Transitional and XHTML 1.0 Transitional.
This has nothing to do with XHTML vs HTML, and everything to do with Strict vs Transitional.
If you want to use old-school design with target, you need to use the old-school document type declaration (Transitional).Birnam wood is come to Dunsinane
-
Jan 7, 2008, 11:58 #5
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am using XHTML 1.0 Strict and not Transitional. I want to replace old-school design with "target" by something that will do the same job but not create errors in XHTML 1.0 Strict.
-
Jan 8, 2008, 01:06 #6
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Whatever you replace it with will still be old-school, since this is an old-school concept. The reason this behaviour is deprecated in Strict DTDs is that it should be up to the user to decide where links open.
Let me rephrase my statement: If you want to control how links are opened, you should use the Transitional doctype declaration.Birnam wood is come to Dunsinane
-
Jan 8, 2008, 06:48 #7
- Join Date
- Nov 2006
- Posts
- 99
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Maybe you can add an custom attribute i.e. 'mytarget' to the tag (link) with value 'preview' and then as a parameter to function makeNewWindow, instead 'this.target' to use 'this.mytarget'?
-
Jan 8, 2008, 07:02 #8
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
That wouldn't exactly help in making the markup valid XHTML.
Birnam wood is come to Dunsinane
-
Jan 8, 2008, 16:42 #9
- Join Date
- Nov 2006
- Posts
- 99
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I meant to 'add an custom attribute' with javascript:
Code JavaScript:linkElement.mytarget = 'preview';
-
Jan 8, 2008, 17:29 #10
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The reason this behaviour is deprecated in Strict DTDs is that it should be up to the user to decide where links open.
linkElement.mytarget = 'preview';
-
Jan 9, 2008, 00:29 #11
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
-
Jan 9, 2008, 00:46 #12
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
If you're going to stick with XHTML then you're going to have to play by XHTML.
Because XHTML has an eye on becoming XML, the target attribute is no longer supported. You will need to rely on javascript to perform the desired action instead.
-
Jan 9, 2008, 02:26 #13
- Join Date
- Nov 2004
- Location
- Ankh-Morpork
- Posts
- 12,158
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Please see post #4 above. This has nothing to do with XHTML. The target attribute is invalid in Strict DTDs (including HTML 4.01 Strict) and valid in Transitional DTDs (including XHTML 1.0 Transitional).
It's about modern vs old-school, not about HTML vs X(HT)ML.Birnam wood is come to Dunsinane
-
Jan 9, 2008, 02:31 #14
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
Thanks for clarifying that, I know it can be a touchy topic.
I have been considering moving back to HTML 4.01 Strict instead of working in XHTML for some time now, and mostly because of the IE issues with XHTML feel that it's going to be a good choice.
-
Jan 9, 2008, 15:54 #15
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's about modern vs old-school, not about HTML vs X(HT)ML.
-
Jan 9, 2008, 16:18 #16
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
The task that the target attribute performs is one that is also easily achieved by javascript.
If your clients have javascript disabled then they will just have to do it manually, otherwise you can use javascript to help them out.
-
Jan 9, 2008, 16:26 #17
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
The task that the target attribute performs is one that is also easily achieved by javascript.
-
Jan 9, 2008, 16:28 #18
- Join Date
- Jan 2007
- Location
- Christchurch, New Zealand
- Posts
- 14,729
- Mentioned
- 104 Post(s)
- Tagged
- 4 Thread(s)
The onclick event is an example of a good place to use javascript.
Code Javascript:<h3>When you click <a href="/home/<?php echo $site_address;?>" onclick="return makeNewWindow(this.href, 'preview')">here</a> you will open a new tab where you will see.... </h3>
-
Jan 9, 2008, 17:04 #19
- Join Date
- Jul 2000
- Location
- Western Massachusetts, USA
- Posts
- 1,389
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks. That works great and validates for XHTML 1.0 Strict.
Bookmarks