[thelist] javascript link to popup window validation issue
Hassan Schroeder
hassan.schroeder at gmail.com
Sat Apr 7 14:11:46 CDT 2007
Joel,
> uh, what? how do I assign 'onclick' on page load?
Offlist, as I'm breaking my own rule about advising people to not use
libraries until they're familiar with the underlying basics :-)
Attaching events to DOM objects does keep your markup a lot cleaner
but the differences between IE and ${everyone else} are a pain in the
butt... Using a JS library like prototype (http://prototypejs.org/) can be a
huge help, though it (of course) also involves a learning curve.
So for your example above, you'd most simply add an id to the link, e.g.
<a id="iaaw" href="/g/IAmAWoman.asp">...</a>
and then something like this in the head:
<script type="text/javascript" src="/lib/prototype.js"></script>
<script type="text/javascript">
Event.observe(window, 'load', function(ev){
Event.observe($('iaaw'),'click',IAmAWoman);
Event.stop(ev);});
</script>
The non-library-aided way might be something like
<script type="text/javascript">
function init()
{
document.getElementById("iaaw").onclick = IAmAWoman;
}
if ( window.attachEvent ) {
window.attachEvent("onload",init);
}
else if ( window.addEventListener ) {
window.addEventListener("load",init,true);
}
</script>
Food for thought, perhaps, and if you spend much time doing JS stuff,
it'll be time well spent to check out prototype, jquery, YUI, dojo, etc.
FWIW!
--
Hassan Schroeder ------------------------ hassan.schroeder at gmail.com
More information about the thelist
mailing list