Html Onload - Using Variables As Parameters
I want to use something like: Unfortunately, this does work, as the quotes in the parameter are not treat
Solution 1:
You would have to use HTML entities to make it work:
<bodyonLoad="init('A sentence with "quoted text" as parameter')">
the much cleaner way, though, would be to assign the value in a separate <SCRIPT>
part in the document's head.
...
<script>
body.onload = function() { init('A sentence with "quoted text" as parameter'); }
</script><body>
...
the onload
event has the general downside that it is fired only when the document and all its assets (images, style sheets...) have been loaded. This is where the onDOMLoad event comes in: It fires when the core HTML structure is ready, and all elements are rendered. It is not uniformly supported across browsers, though, so all frameworks have their own implementation of it.
The jQuery version is called .ready()
.
Solution 2:
Rather than inlining the onLoad
method, why not set it programatically. You can then use the power of closures to get the data into the function.
<scripttype="text/javascript">var data = "some data";
document.body.onload = function()
{
alert(data);
}
</script>
Solution 3:
not the nicest way
onload='init("A sentence with \"quoted text\" as parameter")'
Post a Comment for "Html Onload - Using Variables As Parameters"