Forums » Saxon-CE help »
<script> elements not loaded when
Added by Frederik Tilkin over 9 years ago
Using <xsl:result-document href="#html"> to render the generated html to an iframe, it seems that the <script src="..."> elements are being loaded but the loaded scripts are not executed.
I had a similar problem with not being executed but I solved that by calling that my_onload script at the end of the body.
But this other thing is more of an issue for me. Otherwise I'd have to include all the necessary javascript libraries inline (that's what I do now), but it would be great if that could be avoided.
Any ideas?
Replies (5)
Please register to reply
RE: <script> elements not loaded when - Added by Michael Kay over 9 years ago
I'm a bit surprised that you would expect this to work. If you created a script element dynamically in the DOM using Javascript, would the script get executed? I would have thought you would want control over when the script is executed, that is, you would want to fire it off explicitly. There are surely plenty of ways of doing that.
RE: <script> elements not loaded when - Added by Frederik Tilkin over 9 years ago
Michael Kay wrote:
I'm a bit surprised that you would expect this to work. If you created a script element dynamically in the DOM using Javascript, would the script get executed? I would have thought you would want control over when the script is executed, that is, you would want to fire it off explicitly. There are surely plenty of ways of doing that.
As you can see here: http://stackoverflow.com/a/6433770 , if the script code is inline, the script would be executed, and rightfully so, because if probably defines functions or variables that you'd like to call later on.
Why would an added <script src="jquery.js"> behave differently from an added <script>console.log('hello')</script> ?
<script> elements always behave in the same way, but apparently not when replacing the html node. I don't really see a reason for this inconsistency. I'll probably find a way around this, but it's just another workaround that I'd rather avoid.RE: <script> elements not loaded when - Added by Michael Kay over 9 years ago
When you use Saxon-CE to add the element <script>console.log('hello')</script>
, does the code execute?
RE: <script> elements not loaded when - Added by Frederik Tilkin over 9 years ago
Michael Kay wrote:
When you use Saxon-CE to add the element
<script>console.log('hello')</script>
, does the code execute?
Yes, (well I was replacing the entire html element of an iframe) and when the head contains
<script>console.log('hello') /* in reality the jQuery code */</script>
this is being executed
but when I replaced this by (for example)
<script src="jquery.js"></script>
Things stopped working saying that jQuery was not defined.
I also found out that the onload will probably not fire because I didn't change the href of the iframe, so this might be related in some way.
So I don't think it is an issue with Saxon-CE, it's just something that doesn't entirely work as I'd have expected. (I'm working in Chrome currently.)
RE: <script> elements not loaded when - Added by Frederik Tilkin over 9 years ago
Aargh,
my mistake.
The scripts are being loaded, even in case 2, but by then the initialization code that is inlined at the end of the body has already run (= before the needed scripts have been loaded).
Please register to reply