Newbie question - open new window in XHTML 1.1 document

S

Sam

Hi All,

I am trying to open a new window from a XHTML 1.1 document. The following
code works but I am not happy with having to put the current page name as a
literal. Change the page filename, change all literal references to it.

<a href="javascript:location='current page';
window.open('http://newurl')">Link</a>

Also, the current page is reloaded so you will loose your page location
(urlpage#location) in the current browser window.

How can these problems be resolved?

Thanks

Sam
 
C

Christopher Benson-Manica

Sam said:
I am trying to open a new window from a XHTML 1.1 document. The following
code works but I am not happy with having to put the current page name as a
literal. Change the page filename, change all literal references to it.
<a href="javascript:location='current page';
window.open('http://newurl')">Link</a>
Also, the current page is reloaded so you will loose your page location
(urlpage#location) in the current browser window.
How can these problems be resolved?

The second problem is a snap to resolve. Just lose the
location='current page' - if you don't want the page to reload, don't
reload the page :)

If I understand your second problem correctly, your options are not
great. If these scripts aren't being generated by a CGI, the option
most likely to get the results you want is to have a script source
file that you include from all pages you want to open this url, and in
that file define a variable

var myPageUrl='http://this.url.changes.frequently';

and call window.open( myPageUrl ); Is there any particular reason you
can't simply choose a page filename and go with it?
 
D

David Dorward

Sam said:
I am trying to open a new window

Almost always a bad idea:
http://diveintoaccessibility.org/day_16_not_opening_new_windows.html
from a XHTML 1.1 document.

Why are you using XHTML 1.1? It has few benefits over XHTML 1.0 and lacks
the compatibility fudge that allows you to serve it as text/html (and thus
"work" in user agents such as GoogleBot and Internet Explorer). (For that
matter, XHTML 1.0 has few benefits over HTML 4.01, and comes with a bunch
of gotchas that make it more trouble then its worth in almost ever case).

The following code works but I am not happy with having to put the current
page name as a literal. Change the page filename, change all literal
references to it.
<a href="javascript:location='current page';
window.open('http://newurl')">Link</a>
http://jibbering.com/faq/#FAQ4_24

Also, the current page is reloaded so you will loose your page location
(urlpage#location) in the current browser window.

<a href="http://newURL" onclick="if (window.open) { window.open(this.href);
return false; }">

.... but just using the window the user provides you with is a *much* better
idea.
 
S

Sam

Thanks people for all the help!

I've bookmarked that FAQ so I will look up this before I bother you gurus
too much!

Sam
 
R

Randy Webb

Christopher Benson-Manica said the following on 12/21/2005 12:27 PM:
Is that prefereable to href="javascript:void(0)"?

Neither is actually "preferable" as they both have problems. A better
solution would be along the lines of something like this:

<a href="http://newurl" onclick="return tryNewWindow(this.href)">

function tryNewWindow(newHREF){
if (window.open) { window.open(newHREF);
return false; }
return true;
}

That still needs some more work but its a start. The existence of
window.open doesn't guarantee you get a new window. Norton being a prime
example of a situation where it still wouldn't work.
 
T

Thomas 'PointedEars' Lahn

Kevin said:
I read that a lot, but doesn't the spec say that XHTML 1.1 _should_ be
served as application/xhtml+xml (or application/xml):

http://www.w3.org/TR/xhtml-media-types/#summary

No, it is a W3C Note that says so (which does not make it less correct,
however). It appears that the XHTML 1.1 Specifications does not say
anything about that.

The Note says that XHTML 1.1 SHOULD NOT be served as text/html (read: doing
so is not recommended, see below), which leaves "XHTML 1.1 SHOULD be served
as application/xhtml+xml" as recommended choice according to the table
there. That is why XHTML 1.1 introduces _another_ disadvantage _in
addition_ to that XHTML 1.0 already introduces when it comes to UAs that
do not support XHTML at all, like IE. Which is what David stated.


You are citing from a superseded edition of the XHTML 1.0 Specification,
while this regards XHTML 1.1. It think citing the XHTML 1.1 Specification
is more appropriate here which refers to RFC2119 without change of the
meaning of the keywords defined there:

| The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
| "SHOULD", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are
| to be interpreted as described in [RFC2119].

Unfortunately, it appears the XHTML 1.1 Specification says anything about
the media type that should be used. However, the same definition applies
to

| http://www.w3.org/TR/xhtml-media-types/#summary

which you also referred to. That leaves us with

,-[RFC2119]
|
| [...]
| 3. SHOULD This word, or the adjective "RECOMMENDED", mean that there
| may exist valid reasons in particular circumstances to ignore a
| particular item, but the full implications must be understood and
| carefully weighed before choosing a different course.
|
| 4. SHOULD NOT This phrase, or the phrase "NOT RECOMMENDED" mean that
| there may exist valid reasons in particular circumstances when the
| particular behavior is acceptable or even useful, but the full
| implications should be understood and the case carefully weighed
| before implementing any behavior described with this label.

XHTML 1.0 Appendix C is flawed. XHTML cannot always be written in a way
that it is HTML-compatible. It can _maybe_ only be written in a way that
it is tagsoup parser-compatible.


PointedEars
 
J

Jonas Raoni

I think the prettier solution I see for this xhtml stuff is to do
something like:

<a href="theurl.htm" rel="external">link</a>

And call this on the end of the page...

obs: I used my own addEvent
[http://jsfromhell.com/geral/event-listener] which always supply the
preventDefault and some other things that I need often...

(function(){
function newWindow(e){
e.preventDefault(open(this.href, "", ""));
}
if(window.open)
for(var l = document.links, i = l.length; i;
/external/i.test(l[--i].rel) && addEvent(l, "click", newWindow));
})();
 
T

Thomas 'PointedEars' Lahn

Jonas said:
I think the prettier solution I see for this xhtml stuff is to do
something like:

<a href="theurl.htm" rel="external">link</a>

The value of the `a' element's `rel' attribute must be of type %LinkTypes.

<URL:http://www.w3.org/TR/html4/struct/links.html#adef-rel>
And call this on the end of the page...

obs: I used my own addEvent
[http://jsfromhell.com/geral/event-listener] which always supply the
preventDefault and some other things that I need often...

(function(){
function newWindow(e){
e.preventDefault(open(this.href, "", "")); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
}
if(window.open)
for(var l = document.links, i = l.length; i;
/external/i.test(l[--i].rel) && addEvent(l, "click", newWindow));
})();


Strikes me as being pure fantasy syntax --

<URL:http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-Event-preventDefault>
<URL:http://developer.mozilla.org/en/docs/DOM:event.preventDefault>

--, unnecessary (XHTML 1.0 Transitional exists) and counteractive to
usability.


PointedEars
 
J

Jonas Raoni

The value of the `a' element's `rel' attribute must be of type %LinkTypes.

omg xD

Well, he can use the class property instead of the rel, it sounds
strange, but it isn't soo much, he could even make a different
decoration for the link haha :]
Strikes me as being pure fantasy syntax

It is...
Unnecessary (XHTML 1.0 Transitional exists) and counteractive to usability

Yeah... I just tried to show a solution for him, to keep using the
xhtml 1.1 ;]

He could also add the "target" module
[http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_targetmodule]...

But popups are evil, the user must have control over his windows...
 
T

Thomas 'PointedEars' Lahn

Jonas Raoni wrote:
^^
There are two spaces, you may want to fix this.

Please provide attribution of quoted material.
Yeah... I just tried to show a solution for him, to keep using the
xhtml 1.1 ;]

Why would someone want to use a document type on the Web that the
most widely distributed Web user agent does not even support?
(rhetorical question)
He could also add the "target" module
[http://www.w3.org/TR/xhtml-modularization/abstract_modules.html#s_targetmodule]...

Now /that/ is really interesting. Thanks! :)
But popups are evil, the user must have control over his windows...
ACK

Signatures are to be delimited with a line containing only
MinusMinusSpaceNewline and should not exceed 4 lines.


Regards,
PointedEars
 
J

Jonas Raoni

Thomas 'PointedEars' Lahn escreveu:
Jonas Raoni wrote:
There are two spaces, you may want to fix this.

Hahaha, how unuseful! Thanks :D

Please provide attribution of quoted material.
<URL:http://www.safalra.com/special/googlegroupsreply/>

Ok :)
Why would someone want to use a document type on the Web that the
most widely distributed Web user agent does not even support?
(rhetorical question)

I don't know, people like to be on the top of the technology, sometimes
it doesn't matter if it's good or not... There's nothing wrong with
html 4, but if someone use it, people will call him deprecated :]
Signatures are to be delimited with a line containing only
MinusMinusSpaceNewline and should not exceed 4 lines.

I hope it's better now haha.
 
T

Thomas 'PointedEars' Lahn

Jonas said:
Thomas 'PointedEars' Lahn escreveu:

I don't know, people like to be on the top of the technology,
sometimes it doesn't matter if it's good or not...

It certainly matters if it works or not.
There's nothing wrong with html 4, but if someone use it,
people will call him deprecated :]

Certainly I will not be among the latter. And if someone is,
he is just clueless and can and should be corrected.
I hope it's better now haha.

It is, thanks.


PointedEars
 
J

John W. Kennedy

Thomas said:
Why would someone want to use a document type on the Web that the
most widely distributed Web user agent does not even support?
(rhetorical question)

To defy organized crime?

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
T

Thomas 'PointedEars' Lahn

John said:
To defy organized crime?

Point taken :)

But seriously, using XHTML, especially version 1.1, nowadays on the
Web when HTML would have sufficed is really shooting in your foot.


Regards,
PointedEars
 
M

Michael Winter

On 22/12/2005 23:14, Kevin Newman wrote:

[snip]

Please trim quotes.
IE's lack of support for [application/xhtml+xml] might be a valid
reason [to ignore the recommendation and serve it as text/html].

Hardly. Just don't output XHTML. If XML tools are utilised, ensure that
they transform the output into HTML, first.

[snip]

Mike
 
J

John W. Kennedy

Thomas said:
Point taken :)

But seriously, using XHTML, especially version 1.1, nowadays on the
Web when HTML would have sufficed is really shooting in your foot.

On my personal website, I have some edited 18th-century literary
documents that I make available in both HTML 4.01 Strict and XHTML 1.1
Strict format for those who may wish to download and analyze them, with
selector pages explaining exactly why it was necessary to have two
different versions. (There are other differences; the XHTML versions
also make use of the <q> tag, also left out in the cold by Bill "I
invented the Internet" Gates.)

At some point, there's going to have to be a collective rising up to
say, "Internet Explorer is not a web browser", or we may as well just
all move to AOL.

--
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
-- Charles Williams. "Judgement at Chelmsford"
 
T

Thomas 'PointedEars' Lahn

Kevin said:
Thomas said:
Kevin Newman wrote:

[Full quote]

As Michael said.
Right, which is why I said that if you use XHTML you are basically
asking it to perform double duty (acting like an XML file, but also
acting like an html file, or tag soup if you prefer).

No, and that is not what I meant. Just do not serve XHTML as text/html
because it will then be only food for wrongfully error-correcting tagsoup
parsers, or result in a either syntax error or other unwanted display with
SGML/HTML parsers.
[...] just to add some more cons, pages served with a content type of
application/xhtml+xml gets scanned by virus scanners, which could slow
down the application on some computers (though it might be a minor
concern):
[...]

That does not make sense. Why would resources served as
application/xhtml+xml be scanned and those served as text/html would not?
Either one could refer to harmful content, and either one could not. That
is, neither one strikes me as being harmful by itself, only when it refers
to external resources. CMIIW.


PointedEars
 
T

Thomas 'PointedEars' Lahn

John said:
Thomas said:
Point taken :)

But seriously, using XHTML, especially version 1.1, nowadays on the
Web when HTML would have sufficed is really shooting in your foot.

On my personal website, I have some edited 18th-century literary
documents that I make available in both HTML 4.01 Strict and XHTML 1.1
Strict format [...]

Yeah, I am _not_ at all against valid _alternative_ versions or occurrences
where it is _necessary_ to use XHTML (such as MathML or CML, for example).
At some point, there's going to have to be a collective rising up to
say, "Internet Explorer is not a web browser",

I'd like that :)
or we may as well just all move to AOL.

I do not know about you, but /I/ do not need AOHell for having a decent
web browser :)


Regards,
PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top