Forum Moderators: open

Message Too Old, No Replies

target=_blank

It upsets my validation for 4.01 strict

         

D_Blackwell

10:48 pm on Aug 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a slide show that needs to open to its own window -- because it is so easy to think that you are closing it, and actually close the browser instead.

Adding target=_blank to the href fixed the problem, but now the page doesn't validate for 4.01 strict. It comes up as an unallowed attribute.

---there is no attribute "TARGET" (explain...).
<a href="images/slide-show/default.htm" target=_blank>---

The owner couldn't care less, but I do. What are my options? And where should I go to learn a little more about targets or target substitutes?

Ryan8720

11:06 pm on Aug 31, 2003 (gmt 0)

10+ Year Member



The target attribute is not allowed in HTML 4.01 Strict. The easiest thing to do is use HTML 4.01 Transitional. Otherwise, just ignore it since the client doesn't care.

D_Blackwell

11:53 pm on Aug 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Validation has been a great educational tool for me. I hate to take a step back. Surely there is a valid option? As there valid reasons for wanting to open a new window, there must be a correct method? I'd like to do it properly now, so that I can continue to do so.

Using things now, 'because they work', has on occasion been my downfall later. Once I let that bad habit slip through, it gets easier and easier to reach for it again and again.

jbinbpt

11:58 pm on Aug 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Valdiation is a great learning tool, but should not get in the way of what you need to do. You found a work around that works. Test it in all browsers and be happy with it. I agree with Ryan8720 to validate in HTML 4.01 Transitional.

tedster

12:00 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's another thread that's right on topic for you:

[webmasterworld.com...]

The only valid approach with a strict doctype involves javascript in some fashion. Either that or not forcing the browser to open a new window. The target attribute is really part of a frameset DTD.

pageoneresults

12:00 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd say stick with the strick and be creative in your solution. You could use an <iframe>, you could also use javascript. There are different options available to you, unfortunately they leave a certain percentage of your audience without that functionality unless you provide an alternative for those browsers that are challenged.

tedster

12:15 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the validator throws only one kind of error (your target attributes) then I agree with pageoneresults -- stay with the strict doctype. No browser is going to refuse executing the target attribute, and your code will be pristine but for one exception. This is a great approach, IMO, except that you have no right to post the W3C logo. Does that really matter?

The W3C's handling of the target attribute in strict doctypes has been a source of more than a little controversy. But the rest of the DTD's dictates are well worth retaining even if you are reluctant to throw in javascript or dump the practice of opening a new window.

txbakers

1:38 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If he were to validate in transitional he could use the W3C logo becuase it would validate.

But I agree with everyone else, what's the point? Just so that the validation police are happy?

Why does the end user care what a bunch of ivory tower academics think about a valid atttribute?

D_Blackwell

3:40 am on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good food for thought here. Thanks. I haven't decided what to do yet.

Looks like there isn't going to be the quick and correct fix that I had expected.

I can see why ---"The W3C's handling of the target attribute in strict doctypes has been a source of more than a little controversy.--- Seems like there is a gap to me. Why shouldn't it be fairly easy to open a new window and still validate for strict? It doesn't come up often for me because I generally don't like to open new windows, but sometimes it can be very helpful to do so.

ronin

5:02 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



D_Blackwell>

If you're content to use JavaScript there is a quick and easy fix which validates in both HTML 4.01 strict and XHTML 1.0 strict.

Simply replace:

<a href="http://www.mysite.com/mylink.html" target="_blank">
Link Text
</a>

with

<a href="#" onclick="window.open('http://www.mysite.com/mylink.html'); return true">
Link Text
</a>

[without linebreaks]

D_Blackwell

6:14 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



ronin -- Thanks.

Tried it out and it worked perfectly. My Javascript is really limited except for a small library of tricks, to which I will add this one.

The site is @50 pages and every one validates for HTML and CSS. I really didn't want to make an exception if I didn't have to. While I will make exceptions when necessary, pushing to meet standards has really raised the quality of my work.

Probably wouldn't have asked for the necessary script, but may now decide to upload this option.

There really should be some simple and 'approved' mark-up for this.

Ryan8720

6:31 pm on Sep 1, 2003 (gmt 0)

10+ Year Member



Just keep in mind that if the user has JavaScript disabled, or a popup blocker on, the link won't work.

Also, for future reference, it's good to get in the habit of quoting all your attributes. target="_blank" :)

MonkeeSage

6:56 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I use this:

<a href="blah.htm" onclick="void(window.open(this.href, '', '')); return false;">Blah</a>

That way the SEs like it because it has a valid href, and if the user has JS disabled the link still works it just opens in the current window instead of a new one.

Jordan

g1smd

9:46 pm on Sep 1, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeah, best to cover both options, like in that final example.

ronin

4:07 am on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



MonkeeSage>

Oh, that's brilliant. That fits exactly what I was looking for. Now I can get rid of the ropey old code I volunteered higher up and use your example instead. Ta.

D_Blackwell

5:00 am on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got the first Javascript suggestion to work easily but this 'upgraded' one has me stuck.

<a href="images/galleries/slide-show.html/" onclick="void(window.open(this.href, '', '')); return false;">BLAHBLAH</a>

I reference the file location but don't at all understand what is required for (this.href, ", ")?

MonkeeSage

4:07 pm on Sep 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



D_Blackwell:

"this" means the object that the JavaScript appears in, in this case the link, ".href" is the attribute of "this" that is being referenced, the first '' is the target if you want to re-use the new window, the second '' are any window features you want to specifically enable or disable.

Jordan