K
knocte
Hello.
I am a web developer very worried about "bloat code" and "languages
mixture". So, since some time, I always try to avoid completely the use
of javascript in XHTML/HTML files. This leads to me to hate, also, any
event (onload, onchange, ...) instanciated in the element tag itself, like:
<input type="text" onkeyup="return doSomething();" />
I would replace this code above with an input element marked with an
"id" attribute, and append a JS file to the header with the following
content:
function doSomething(){
[...]
}
function ApplyEvents(){
document.getElementById("mytextinput").onkeyup = doSomething;
}
window.onload = ApplyEvents;
I think that all people who read this would agree that this method is
very smart and gentle.
But it has a very big problem: sometimes, when the XHTML/HTML page is
very large, the ApplyEvents function gets called to late. For example,
when the page is loaded, the user has usually been able to use some
HTML/XHTML controls so as to cause the page to fire some events, but
they are ignored.
I have thought also about using <script> elements just after each tag
element to which I want to apply an event, but I think this is a bit dirty.
Do you know a better method to apply events without mixing javascript
with the markup or using events on the XHTML/HTML source? If I was a
person in charge of suggesting XHTML 2.0 capabilities, I would propose a
new event for the window, for example: onnodeload. This way I could
apply events whenever a new tag has arrived from the server to the
rendering client.
Regards,
Andrew
--
I am a web developer very worried about "bloat code" and "languages
mixture". So, since some time, I always try to avoid completely the use
of javascript in XHTML/HTML files. This leads to me to hate, also, any
event (onload, onchange, ...) instanciated in the element tag itself, like:
<input type="text" onkeyup="return doSomething();" />
I would replace this code above with an input element marked with an
"id" attribute, and append a JS file to the header with the following
content:
function doSomething(){
[...]
}
function ApplyEvents(){
document.getElementById("mytextinput").onkeyup = doSomething;
}
window.onload = ApplyEvents;
I think that all people who read this would agree that this method is
very smart and gentle.
But it has a very big problem: sometimes, when the XHTML/HTML page is
very large, the ApplyEvents function gets called to late. For example,
when the page is loaded, the user has usually been able to use some
HTML/XHTML controls so as to cause the page to fire some events, but
they are ignored.
I have thought also about using <script> elements just after each tag
element to which I want to apply an event, but I think this is a bit dirty.
Do you know a better method to apply events without mixing javascript
with the markup or using events on the XHTML/HTML source? If I was a
person in charge of suggesting XHTML 2.0 capabilities, I would propose a
new event for the window, for example: onnodeload. This way I could
apply events whenever a new tag has arrived from the server to the
rendering client.
Regards,
Andrew
--