I'm using an html script tag with the src attribute as follows:
<script src="http://...">
</script>
I need to also put a bit more code to redirect the page after the script has run - is it valid/acceptable to add the script between the existing script tags or should I add another script on the end?
This:
<script src="http://...">
...do something else he
</script>
Or:
<script src="http://...">
</script>
<script>
...my other code here
</script>
No it can't.
Use the bottom one.
The long answer…
w3c states
“The SCRIPT element places a script within a document. This element may appear any number of times in the HEAD or BODY of an HTML document.
The script may be defined within the contents of the SCRIPT element or in an external file. If the src attribute is not set, user agents must interpret the contents of the element as the script. If the src has a URI value, user agents must ignore the element's contents and retrieve the script via the URI.”
Source: http://www.w3.org/TR/html401/interact/scripts.html
Oh, boy. you can't write code inside the script tag having src tag.
You have to use different script tags.
As js loads top to bottom. Your code will work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With