Re: Scripting Techniques first draft

Mirabella, Mathew J wrote:

> 
> I am not sure to what extent you should replicate function calls with
> onClick, onKeypress and onActivate, but here they all are.  

onkeypress raises a major problem on Firefox and Opera. When tabbing 
through a document the event will be fired when tabbing off the link, 
hence unexpectedly opening or closing windows!

I don't think we should be promoting onactivate. It is part of the IE 
Dom and poorly supported besides which onclick is device independent in 
most browsers now (Bug 490 - 16.3 of HTML Techniques).

> Now for the close window link...
> 
> In the html of document.html:
> <script language="JavaScript" type="text/javascript">
> <!--
> document.write ('<a href="#" title="Close This Window"
> onClick="window.close();  return false;" onKeyPress="window.close();
> return false;" onActivate="window.close(); return false;">Close This
> Window</a></li>');
> // -->
> </script>

You could supplement this by testing for the presence of an opener 
object before displaying the 'Close Window' link.
ie If a user does not arrive at the page through a pop-up (eg from a 
bookmark) the 'close window' link is not relevant.

if (window.opener) {
   var link = document.createElement('button');
   link.setAttribute('title', 'Close this window');
   link.onclick = function() {
     window.close();
   }
   link.appendChild(document.createTextNode('Close This Window'));
   document.getElementsByTagName('body').item(0).appendChild(link);
}

> <noscript>
> Use your browser functions to close this window.
> </noscript>

It should be emphasised that this is only relevant with a Transitional 
DTD. The TARGET attribute is not valid in the Strict Doctype, so, in 
absence of a target and with no scripts enabled the document would open 
in the same window, rendering the above statement misleading.

Cheers, Tom

Received on Wednesday, 15 September 2004 04:09:34 UTC