I need to go on holiday more often, if people come up with smart ideas like HTML overlays while I am away. Kudos to Dan Glazman and Laurent Jouanneau of Disruptive Innovations (obviously a wise hiring, Dan :-).
My first thought is: if and when we get browsers with native overlay support, how do you prevent the backwards-compatibility JavaScript executing and thereby including two copies of the overlay contents? You'd need to mark the script in some way to indicate that it was the special overlaying script, so the UA could ignore it. I see four options, all horrible:
Any more ideas for solving this problem?
Posted by gerv at September 6, 2004 8:32 PMHTMLoverlays.js:
if (!browserSupportsOverlays())
{
// do overlay compatibility stuff
}
Nicholas: how would you write the "browserSupportsOverlays()" function in a way that meant it didn't have to be updated when new browsers were released?
Gerv
Posted by: Gerv at September 6, 2004 10:47 PMWhat about using the version attribute for something useful? :)
Or perhaps add a freaky var to the script:
var MOZILLA_ORG___THIS_CONST_SHOULD_NEVER_BE_USED_UNLESS_YOU_KNOW_WHAT_YOU_ARE_DOING___GOT_IT_ = 1;
;)
Posted by: Vidar Braut Haarr at September 6, 2004 10:57 PMErm, it seems my HTML code was removed:
<script version="HTMLOverlay" src="." />
Gerv: maybe write it in a way that contains those known not to work then? IE, check for UAs of those known not to work?
Posted by: dantealiegri at September 6, 2004 11:00 PMfunction browserSupportsOverlays()
{
return typeof(document.supportsHtmlOverlays) != "undefined" && document.supportsHtmlOverlays;
}
or something to that effect.
Of course, if all this can be done with scripting, why bother with explicit browser support?
Posted by: Nicholas at September 7, 2004 1:56 AMYou pinged me about it yesterday night, so I spent a few hours on the problem. I see only one solution that (a) is compatible with legacy browsers (b) is not intrusive and declarative.
The solution is "something like" two new attributes called "ifsupported" and "ifnotsupported". Just don't comment on the names please, that's not the important point here.
The attributes' value is a comma-separated list of the following functional notations:
where all arguments are strings.
The two attributes are not exclusive. The element carrying the attributes is rendered/loaded/applied/executed/whatever only if all the conditions specified in the "ifsupported" attribute are true and all the conditions specified in the "ifnotsupported" attribute are false.
That way, you could just write:
<script src="HTMLOverlays.js" ifnotsupported="feature('HTMLOverlays')" ... />
No JS, extensible to any other HTML element, easily replaces NOFRAMES and NOSCRIPT element, object-friendly, etc. Furthermore, the attributes won't be understood by legacy browsers, so they will load and apply the script anyway.
I am pretty sure that the HTML Keepers of the Temple are going to scream about it, but I think it's a nice solution that solves backwards compatibility in a quite simple way.
Daniel
Posted by: Daniel Glazman at September 7, 2004 8:46 AMwhy not just use
document.implementation.hasFeature("moz-overlays","1.0")
in the script? Or call the whatwg-overlays ;-)
Posted by: Axel Hecht at September 7, 2004 9:50 AMAxel: because if document.implementation.hasFeature ... is not defined, it will spark an error.
try{}catch{} is not supported in all UA's, and any solution which involves JS is just "bloat" on this that really shouldnt need to be hacked in to support a new UA feature, such as overlays.
Posted by: Justin Wood (Callek) at September 7, 2004 10:03 AMand because you don't want to load the script at all if you can avoid it...
Posted by: Daniel Glazman at September 7, 2004 10:53 AMI have found a better way IMHO:
change the content model of the link element in new browsers to accept script and link element. Those inner script and link elements are used as a fallback if the rel/rev attributes on the link element are not recognized by the user-agent.
for example:
<link rel="HTMLoverlay" href="myoverlay.xml"> <script src="HTMLoverlay.js" ....> </link>
Legacy browsers accept it w/o problem and load the script, new browsers supporting rel="HTMLoverlay" drop the script element:-)
Posted by: Daniel Glazman at September 7, 2004 12:00 PMDaniel,
The latter wont feasably work, IMHO...
is defined as "must be empty" in HTML 4.01... many UA's will never understand it to be filled, and if we allow it to be, are we not *effectively* breaking old pages?
we could always use of course, but that defeats half the purpose of this (since we would need a mime-type for the overlay).
Posted by: Justin Wood (Callek) at September 7, 2004 3:13 PMok it ate my html <link /> was to go before the work "is" on the second sentance.
Posted by: Justin Wood (Callek) at September 7, 2004 3:14 PMCallek: according to my tests, at least Gecko-based browsers and all flavors of IE I have here can accept that non-empty LINK.
Posted by: Daniel Glazman at September 7, 2004 8:09 PMOf course, if all this can be done with scripting, why bother with explicit browser support?
Because you may want overlays to continue to work if JS is turned off, and you may want to support overlays in e.g. Lynx, which doesn't support JS at all.
change the content model of the link element in new browsers to accept script and link element.
That's really smart :-) I like that a lot, and it works in the same way as e.g. <object>. Could this extension to the HTML spec be a WHATWG thing?
Posted by: Gerv at September 7, 2004 11:38 PMCould this extension to the HTML spec be a WHATWG thing?
Why not? Let's ping Hixie.
Posted by: Daniel Glazman at September 9, 2004 9:20 AM