Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
161
rated 0 times [  167] [ 6]  / answers: 1 / hits: 44542  / 14 Years ago, sat, october 23, 2010, 12:00:00

I want to use something like:



<body onLoad=init('A sentence with quoted text as parameter')>


Unfortunately, this does work, as the quotes in the parameter are not treated properly.



Escaping the quotes also does not work



<body onLoad=init('A sentence with quoted text as parameter')>


(Above also does not work).



How do I deal with this. I though maybe I can create a string variable and assigne my sentence (with quotes) to it. But I dont know how to do it! The body onload is HTML and the Javascript variables would be visible only within the scope of the script, right? To be precise, the following does not work:



<script language=JavaScript>
var dada='A sentence with quoted text as parameter';
</script>
<body onLoad=init($dada, '</a>')>

More From » html

 Answers
23

You would have to use HTML entities to make it work:



<body onLoad=init('A sentence with &quot;quoted text&quot; 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().


[#95201] Thursday, October 21, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
hallie

Total Points: 503
Total Questions: 114
Total Answers: 103

Location: Iraq
Member since Fri, Jun 5, 2020
4 Years ago
;