PDA

View Full Version : safari isn't loading <script> functions



wglass
28 Nov 2007, 4:23 PM
Hi,

I have an app which dynamically loads content into a div with ext-js. When a <script> tag is included, any functions within the script tag cannot be called. This works in IE6, IE7, FF 2, but not Safari 3.

The function (it's part of a border layout) that loads the content is here:



loadContent: function(page)
{
this.contentPanel.load(
{
url: page,
text: "Loading...",
timeout: 30,
scripts: true
});


The script (within the HTML that is loaded) is:



<script type="text/javascript">
function validate()
{
alert('test');
return true;
}
</script>


If I try to call it from a button it fails.


<INPUT TYPE="button"NAME="submitsurvey" VALUE="Submit Survey" id="submitsurvey" onClick="return validate();" />


Interestingly, if I include an Ext.onReady within the script tag it is executed. But I can't seem to access the function from a button on the page.

If I move the function to the parent file it will get executed. But it has dynamically generated info in it so I want to be included in the AJAX loaded section.

Again, this works fine in Firefox or IE.

Would appreciate any tips.

Thanks, WILL

hendricd
28 Nov 2007, 4:27 PM
Aside from the fact Safari 3 is still beta, try:


<script type="text/javascript">
validate=function()
{
alert('test');
return true;
}
</script>

wglass
28 Nov 2007, 6:19 PM
Thanks!

That worked. Though if I include a "var" before the variable name it doesn't.

It's still a bug though. Not sure if it's in EXT-JS or in Safari.

I'm worried about regression problems-- it's going to be hard to have the discipline to do all the Javascript functions in a manner that avoids this quirk.

WILL

hendricd
28 Nov 2007, 9:22 PM
Don't worry, if all goes well, you won't be using inline event handlers any more ;)