View Full Version : How do I use href target in XHTML?
KayJayDK
11-26-2003, 09:02 PM
After switching to CSS I decided to use strict XHTML on my web pages. After a lot of trial and error, I've finally gotten to the point where I can make it do what I (almost) want it to. There are all those weird browser incompabilities and other things you have to learn to live with.
I finally even found out how to make a script block work without the language attribute.
I still have one big problem; how can I get a link to open a new browser window when I can't get the target attribute to validate?
I have another unrelated question that mayby someone can answer. Should I avoid <br> in my text? They seem to somehow not be cosistent with the practice of keeping all text inside two tags, or is that just me?
liorean
11-26-2003, 09:54 PM
Well, yes, you should keep br to a minimum. However, until XHTML2 finilises, there' not many more semantical tags to use.
The easy answer to the target question is, you don't. W3C believes it's up to the user to specify if they WANT a new window or not, not up to the page. You might give the user a suggestion that opening in a new window is better, but the intention is that the control of the user interface, and among it's parts the window itself most prominently, belongs solely to the user. The user may right click and chose to open a new window, but if he doesn't, you shouldn't force him into opening a new window.
However, because of XFrames, the target attribute looks like it will return in XHTML2.
brothercake
11-26-2003, 10:07 PM
You can make line breaks with block-level display:
<p>
Here is some text
<div>and this is a second line</div>
</p>
Since the div is block-level it makes a line-break, but it could be any other element with display set to block.
liorean
11-26-2003, 10:19 PM
Yeah, but that example was invalid. You may not contain a div in a paragraph. However, there is really no semantically better way to do it with the current set of elements in HTML or XHTML. The line element (or if they went with my suggestion and shortened it to l) of XHTML2 will make something semantically better, though.
KayJayDK
11-26-2003, 10:21 PM
Thanks for both the answers. In a way I agree that it should be up to the user. I hate having windows open up by themselves but on the other hand in some situations (when opening an external link from a site you probably don't wnat to leave) it's much easier to just click a link without using the context menu...
For the <br> issue, I actually did something similar in the meantime. My problem with using <p> was that I didn't want too large gaps between my paragraphs in a sidemenu but I configured P to have no marging so now the next line appears just below it as if I used a <br>.
KayJayDK
11-26-2003, 10:29 PM
okay, all 3 answers... I took too long to type my reply ;)
Now everything looks as it should: http://www.divxguide.dk/css/test.asp
However, I got some strange behaviour from my images at the bottom of the left menu bar. They have a dark green background and I cannot get it to go away.
In my CSS I have a class named block which sets up the light green blocks where I have some text and pictures:
#mainLeft .block {
text-align: center;
color: black;
background: #B0E0E6;
padding: 3px 0px 3px 0px;
border-bottom: 1px solid white;
}
#mainLeft .block p {
padding: 3px;
margin: 0px;
}
#mainLeft .block img {
border: 0px;
margin: 0px;
}
I think the dark green bg color is 'inherited' from the previous #mainLeft definitions but I'm not sure how. The CSS is located at http://www.divxguide.dk/css/css/test.css .
Erich
11-26-2003, 10:34 PM
theres always the js solution:
http://www.dynamicdrive.com/dynamicindex8/newwindow.htm
http://www.dynamicdrive.com/dynamicindex8/newwindow2.htm
KayJayDK
11-26-2003, 10:40 PM
Yeah, there's always java. I try to avoid it as much as possible tho. I use a lot of server scripting but not client side. Thanks for the links, they might come in handy anyways.
Btw, I found the problem with the images mentioned in my last post. I forgot the images were inside A tags which were defined earlier under the #mainLeft as a dark green block. I had to re-define the #mainLeft .block a to have no padding, borders or background.
mindlessLemming
11-27-2003, 06:35 AM
Put this inside your <a> tag
[code]
onclick="window.open
<a href="codingforums.com"(this.href, 'popupwindow', 'width=800,height=600,scrollbars,resizable,menubar=1,location=1,toolbar=1'); return false;">
Oh, and it validates as XHTML 1 Strict:thumbsup:
KayJayDK
11-27-2003, 07:54 PM
Thanks. Inline script is not as bad. I guess I can live with that :cool:
brothercake
11-27-2003, 11:33 PM
It still isn't really valid. All that does is fool the validator. If you're really concerned about XHTML conformance then don't open windows at all.
MetalStorm
11-28-2003, 12:51 PM
probably a bit simplier to use something like
<a href="http://whatever" onclick="this.target = '_blank';">whatever</a>
Originally posted by MetalStorm
probably a bit simplier to use something like
<a href="http://whatever" onclick="this.target = '_blank';">whatever</a> But won't that open a new window of the current page and then take the original page to http://whatever, or is it the other way round?
MetalStorm
11-29-2003, 05:38 PM
Originally posted by me'
But won't that open a new window of the current page and then take the original page to http://whatever, or is it the other way round?
it just sets the target attribute to _blank when the link is clicked.
but the real (xhtml) way to get round the problem is not to specify the target at all ofcourse ;)
Madbyggeren
12-03-2003, 05:09 PM
As far as I know, javascript is the only solution atm for producing valid code that will open a new window. However, there is a very easy way to do it:
http://www.sitepoint.com/article/1041/1
The posted article describes the idea behind a script, when - included on the necessary pages - will only require the string
rel="external"
to be added to the <a> tag. Pretty d*rn smart, I find it!
Hope it'll help all you valid-coders! ;)
Best regards
Frederik Schøning
frederik@spacy.dk
liorean
12-03-2003, 06:22 PM
Actually, you can validate towards an XHTML 1.1 with the XLink module, and use XLink to do it if you want, but it's not going to be well supported. Moz handles it and iew needs a HTC to be able to do it, Opera could do something alike with it's proprietary CSS extensions. It will make your XHTML valid, though.
brothercake
12-03-2003, 09:45 PM
I know I've trotted this out before - but it is very funny - jkd's semantic popup :)
<advertisement
xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:type="simple"
xlink:href="http://www.google.com"
xlink:show="new"
xlink:actuate="onLoad"
/>
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.