Hi, I'm having a problem running a javascript function which is embedded in an XSLT and invoked with the body onload event.
Here is the xml, test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<foo></foo>
And here is the xsl, test.xsl:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<script language="javascript" type="text/javascript">
function init () { alert("It worked!"); }
</script>
</head>
<body onload="init();">
<button onclick="init();">Click me</button>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When the xml page loads, there is no alert box which should pop up. However, when I click the button that points to the same javascript function, it works fine. In addition, there is a "init not defined" error message in the error console. I suspect it has something to do with Firefox not having interpreted the javascript before the body onload event is triggered.
This code works fine in IE7--the alert box pops up when the page is initially loaded and when the button is clicked, but I would like to get it to run in Firefox. Any insight or fixes, or maybe pointers to the proper way of invoking javascript are welcome.
----------------------------
觉得分少的 我可以再加