Forum Moderators: open

Message Too Old, No Replies

Appropriate XHTML-Equivalent for target="_blank"

It's forbidden in XHTML 1.1

         

waldemar

2:28 pm on May 14, 2003 (gmt 0)

10+ Year Member



Does anyone know the correct way to allow an xhtml 1.1 page to open new browser windows? As far as I understand target="_blank" is no xhtml attribute, since doesn't have to do anything with the document. So I need to use scripting? Will a simple win=window.open(mypage,myname,settings); do the trick? Is that allowed?

le_gber

2:46 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi waldemar an welcome to WebmasterWorld

I think it's target="_new" but I'm not 100% sure

Leo

globay

3:13 pm on May 14, 2003 (gmt 0)

10+ Year Member



you may want to read this thread:

[webmasterworld.com...]

waldemar

4:10 pm on May 14, 2003 (gmt 0)

10+ Year Member



Hey thanks for the welcome :-)

I think "_new" is not a reserved keyword, it just opens a window with the name "_new" while "_blank" creates a new browser window from the scratch.

globay: thanks, read it. but they didn't come up with a alternative...

So this is my solution for the time being:

<* line break added to prevent side scroll>

<script type="text/javascript">
//<![CDATA[
<!-- Script Start
var win=null;
function newwindow(mypage,myname,w,h)
{
LeftPosition=(screen.width)?(screen.width-w)/2:100;
TopPosition=(screen.height)?(screen.height-h)/2:100;
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',
*scrollbars=0,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
}
// Script End -->
//]]>
</script>

while the link looks like:

<a href="link.htm" onclick="newwindow('link.htm','Loading',xxxxx,yyyyy);return false;"> ......

...which also deals with Non-Javascript-Browsers. Can anyone confirm this is appropriate xhtml-handling?

[edited by: tedster at 9:51 pm (utc) on May 14, 2003]

mozopera

2:29 am on May 13, 2003 (gmt 0)

10+ Year Member



I agree. I use XHTML 1.0 Transitional for the simple reason that I can use target="_top".

waldemar

10:13 am on May 13, 2003 (gmt 0)

10+ Year Member



Wow thanks guys, that's some stuff to work on...

I'm using xhtml 1.1 simply because it's a promotion website for a webdesigner - to sort of show "hey, we can do the latest technolgy" :-)

waldemar

10:36 am on May 13, 2003 (gmt 0)

10+ Year Member



Interesting article... and it works fine :-) only thing I don't quite grasp is then window-open explanation:

"[...] A number of other standards-compliant new-window link scripts out there propose using window.open() to load the document in a new window. While this approach generally works well on the surface, its downfall is that most browsers do not correctly report the referring URL in the request for the new page, which can be a serious issue, especially in inter-site links. [...]"

What do they mean by it doesn't correctly report the referring url?

DrDoc

10:41 am on May 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"hey, we can do the latest technolgy"

but that doesn't mean coding for browsers that can't display it properly ;)

What do they mean by it doesn't correctly report the referring url?

If the target page runs some sort of script that relies on getting a proper HTTP_REFERRER header (to deliver certain content depending on the page you were browsing when you clicked the link)... then window.open() simply won't work.

waldemar

3:56 pm on May 13, 2003 (gmt 0)

10+ Year Member



Valid point. I was wondering if there's a good table somewhere with all browsers and their capabilities and compatibilities... I was testing this xhtml-stuff successfully with ie6 and moz1.x which make above 90% of our visitors - so... why not stick to it (w3c's xhtml1.1-label is just a nice award itself :-). For sure the (tough) decision to not support n4 anymore is through.

Personally I begin to like the "strict"ness of xhtml 1.1 since it's finally a complete and cleaaan system and set of rules without any "transitional" variants :-).

For the new window, this thing is only used to popup a larger view of all the IMGs on the page. Sounds to me like window.open() should be enough (also I can adjust the width and height to the image size).

rainborick

4:09 pm on May 13, 2003 (gmt 0)

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



You can often work around the referral problem with window.open() by passing a genuine URL for a document in the desired domain, as in:

window.open("http://www.mysite.com/somepage.html", pragma);

This cropped up for someone I knew who was using JavaScript-generated pop-up windows to display images that were stored in a directory with .htaccess anti-leeching set up. He was also using JavaScript to dynamically generate the <img> tag contents, so it was a bit complicated. I found that Netscape and MSIE both have their little quirks in this area, but you can work around them without much trouble.

universalis

5:19 pm on May 13, 2003 (gmt 0)

10+ Year Member



I'm using xhtml 1.1 simply because it's a promotion website for a webdesigner - to sort of show "hey, we can do the latest technolgy" :-)

I can see the point of this argument, however I have a few caveats. Firstly, if you want to really show what you can do with XHTML 1.1, then aren't you doing yourself a disservice by resorting to massive hacks like those I described above? I mean, you are just putting the spotlight on one of the limitations inherent in using XHTML 1.1.

Secondly, if you are determined to go for 1.1, then you should seriously consider going the whole distance by serving the pages with the mime-type of

application/xml+xhtml
to those browsers which can cope (principally Mozilla). Beware that if you do that, you can't slip up on the "well-formedness" of your markup, and you may well have to adapt your CSS and Javascript too.

Personally, I use HTML 4.01 Strict for commercial sites, and keep the XHTML for just the experimental stuff. Oh, and I hate it when links open in new windows! :D

Oaf357

6:27 pm on May 13, 2003 (gmt 0)

10+ Year Member



XHTML 1.0 is rather good and when used properly can reduce page sizes. Plus, it just looks better (source) and pages have to meet a higher standard.

waldemar

6:41 pm on May 13, 2003 (gmt 0)

10+ Year Member



(OT: Where is the quote button here?)

univ:

Do you really see this little script as a massive hack? I mean this all happens within all the regulations and recommendations. And by using <a href="link.htm" onclick="newwindow('link.htm','Loading',xxxxx,yyyyy);return false;"> I also cover people without javascripting active...

Hm see it this way... all the thumbnails on the webpage need to be zoomed to show details. This is - without script - happending in a regular Back-available history-style or - when clienscripting is active, which relates to the browser-technique/environment, in a small popup (ANY click will close it).

I hate popups too and - hereby - I promise to never use it - also when leaving the site - except for this image-popup. :-)) What would you suggest for a webgui handling if you had thumbnails on a page and want to provide a clean AND easy way to allow the visitor to see a larger image?

What do you mean with the mime-type 'application/xml+xhtml'? Is defining the doctype not enough? Markup and CSS are optimized already and pass the validator with no problems. (I started upgrading xhtml only several weeks ago, so I apologize for 'newbie'-questions...) I am also not using any propriatery CSS and ANY other javascript (except this popup).

>> Personally, I use HTML 4.01 Strict for commercial sites, and keep the XHTML for just the experimental stuff. Oh, and I hate it when links open in new windows! :D

My way as well, except with some customers here I need to stick to transitional. The idea of using xhtml 1.1 for the promotion site was to kick customers in the butt and say "hey, did you actually know there is a standard out there? and some development? And what b***sh** you get from so many web developers?"

rain:

Thanks, will take that into account. :-)

universalis

7:53 pm on May 13, 2003 (gmt 0)

10+ Year Member



What do you mean with the mime-type 'application/xml+xhtml'? Is defining the doctype not enough?

(OT reply: to quote, use (quote) and (/quote), except with square brackets!)

Sorry to reply with just a bunch of links, but this is a complex matter and others express it better than me.

This article is the best I've found so far which explains MIME types:

[xml.com...]

You might also want to read this opinion about the issue:

[hixie.ch...]

I am not completely averse to XHTML, but a lot of people using it are simply jumping on the bandwagon, rather than making good use of it. There is a lot more to XHTML adding a few trailing slashes and changing the

DOCTYPE
!

I think your Javascript solution sounds very reasonable - when I was talking about a "massive hack", I was referring to my previous suggestion regarding creating a new DTD just to add the target attribute.

waldemar

8:34 pm on May 13, 2003 (gmt 0)

10+ Year Member



Interesting links, I was always wondering... XHTML .... XML .... wait, does that mean, my washing machine (not the current one :-) ) can read my webpages? (Ahhhm, of course it's the mime type - like "mime-type=clothing/wool") This bringes up new challenges; if your web hoster doesn't allow shell access in the way to cusomize your mime types, you will never be able to publish xhtml code? ... hmmm....

Yes, this DTD extension had a little too much overhead for me for just popping some picture zooms :-)

universalis

11:09 pm on May 13, 2003 (gmt 0)

10+ Year Member



This bringes up new challenges; if your web hoster doesn't allow shell access in the way to cusomize your mime types, you will never be able to publish xhtml code?

You don't need shell access, but you do need Apache mod_rewrite or a server-side scripting language. The first article in my previous post gives the code in PHP and Python, and it should be trivial to do the same in ASP or perl.

waldemar

10:07 am on May 14, 2003 (gmt 0)

10+ Year Member



Hm, tried both the php script and the .htaccess rewrites, but the xt w3c validator still shows text/html... :-(

universalis

1:14 pm on May 14, 2003 (gmt 0)

10+ Year Member



Hm, tried both the php script and the .htaccess rewrites, but the xt w3c validator still shows text/html... :-(

I'm not aware that the validator sends an accept header for

application/xml+xhtml
, so it would naturally still show the output as
text/html
. To check, you just need to look in Mozilla (or Netscape 7). Go to View > Page Info (Ctrl+I). You should see "Type:
application/xml+xhtml
" and "Render Mode: Standards Compliance Mode". Don't forget, the script and rewrites only send the MIME type
application/xml+xhtml
to user agents which can cope with it, sending the MIME type
text/html
to everything else.

waldemar

5:19 pm on May 14, 2003 (gmt 0)

10+ Year Member



The author mentioned, it should work in the extendet verbose mode of the validator.

Interesting reader comments are linked to that article. One of them refers to a german article

[schneegans.de...]

which really seems to bring it to the point. Right now it seems not recommendable to do anything in xhtml, since 95% of the used browsers misinterpret the intended xhtml semantic (wether it's the wrong mimetype or stupid bugs).... That's a lot to think about; maybe try xhtml again next year?! :-)

universalis

7:01 pm on May 14, 2003 (gmt 0)

10+ Year Member



Right now it seems not recommendable to do anything in xhtml ...(snip)... That's a lot to think about; maybe try xhtml again next year?! :-)

I can't comment on the article you mention as my German is, erm... limited. You have a legitimate desire to use XHTML (as a way of showcasing the new standard) and you should be able to do so with care. I wouldn't give up just yet!

As I mentioned earlier, I don't use XHTML for commercial sites, and I don't expect to do so for a couple of years yet. However, that doesn't mean that you shouldn't, as long as you are careful. The problem with XHTML is from those sites that treat it as merely as a drop-in replacement for HTML 4, with a few trailing slashes and a namespace declaration. Being aware of and attempting to deal with issues such as the MIME type problem means that you are not likely to create the myriad of problems mentioned in the previous articles.

I admit to being a standards geek, and I use CSS and table-free layouts extensively, but I find that XHTML offers no immediate benefits and have many pitfalls, and is a bandwagon I'm not going to jump on for the moment.

DrDoc

11:54 pm on May 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



About opening links in a new window or not... I always leave it be. If a person wants to open the link in a new window, they will right-click and choose "Open in New Window". Otherwise, they will just click. It's not always good to "force" the link to open in a new window. Might annoy people ;)