These forums are currently read-only due to receiving more spam than actual discussion. Sorry.

It is currently Sat Dec 02, 2017 4:16 pm Advanced search

read script content onload

Do you think the HTML spec should do something differently? You can discuss spec feedback here, but you should send it to the WHATWG mailing list or file a bug in the W3C bugzilla for it to be considered.

read script content onload

Postby PMB9 » Mon Mar 23, 2009 7:38 pm

I do like to have a runon="load" attribute, so the script is beeing interpreted after the page is displayed. So I don't need to take the script tag to the end of the html document. Would be nice to use runon="unload" etc too.

Code: Select all
<script src="very_big_script.js" runon="load"/>
PMB9
<h3>
 
Posts: 50
Joined: Sat Jan 26, 2008 5:38 pm

Postby lyosha » Mon Mar 23, 2009 9:35 pm

Code: Select all
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}


Instead of cluttering the script tag with events, the script itself should take care of events such as window.onDOMContentLoaded. What we need is for all browsers to implement the above (IE and Safari are the two left to implement this).
lyosha
<h3>
 
Posts: 60
Joined: Fri Aug 22, 2008 9:26 pm

jQuery

Postby mskinner » Mon Mar 23, 2009 10:21 pm

jQuery allows one to call the following:

Code: Select all
$(document).ready(function() {
    //Statement 1
    //Statement 2
})
//Other script code or markup
$(document).ready(function() {
    //Statement 3
    //Statement 4
})


So at the top, middle or bottom of "very_big_script.js" you could have a call to:
Code: Select all
$(document).ready(function() {
    very_big_function();
})

Repeated calls do not overwrite previous ones, they are appended.
It's about 20KB, is all inside one file, and is cross browser: http://jquery.com/

Other JavaScript libraries probably have similar features to make life easier too.
mskinner
<h2>
 
Posts: 116
Joined: Sun Jun 24, 2007 12:20 am
Location: Melbourne, Australia

Postby lyosha » Mon Mar 23, 2009 10:43 pm

Yeah, I'm a jQuery fan myself, but I think we should still press for browser support for standard interfaces.
lyosha
<h3>
 
Posts: 60
Joined: Fri Aug 22, 2008 9:26 pm

Postby zcorpan » Tue Mar 24, 2009 9:16 am

HTML5 specifies <script defer> which will make the script run when the document has loaded, IIRC. For unload you could use <body onunload=...>
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Postby PMB9 » Tue Mar 24, 2009 5:02 pm

Great, zcorpan. "defer" is exactly what I mean.

By the way I hope DOMContentLoaded to become a standard, so DOM functions don't have to wait until all images are loaded.
PMB9
<h3>
 
Posts: 50
Joined: Sat Jan 26, 2008 5:38 pm

Postby zcorpan » Wed Mar 25, 2009 10:30 am

HTML5 wrote:The user agent must then fire a simple event called DOMContentLoaded at the Document.
-- http://www.whatwg.org/specs/web-apps/cu ... op-parsing
zcorpan
<article>
 
Posts: 807
Joined: Tue Feb 06, 2007 8:29 pm
Location: Sweden

Re: read script content onload

Postby JAB Creations » Thu Mar 26, 2009 7:29 am

PMB9 wrote:I do like to have a runon="load" attribute...


This is the HTML5 forum, we're not discussing the W3C DOM, Mozilla's JavaScript, or Microsoft's JScript implementations.
User avatar
JAB Creations
<aside>
 
Posts: 566
Joined: Tue Mar 13, 2007 4:48 am
Location: Sarasota Florida, USA

Postby PMB9 » Thu Mar 26, 2009 3:42 pm

JAB Creations, "defer" is a HTML 5 feature and a runon="load" attribute for the script element would be no feature of DOM or Ecmascript, it would be a HTML 5 feature.
PMB9
<h3>
 
Posts: 50
Joined: Sat Jan 26, 2008 5:38 pm


Return to Feedback on the Specs

Who is online

Users browsing this forum: No registered users and 0 guests