Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html script tag - can script be added when src is used

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>
like image 381
dotnetnoob Avatar asked Feb 13 '23 18:02

dotnetnoob


2 Answers

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

like image 164
OrderAndChaos Avatar answered Mar 05 '23 00:03

OrderAndChaos


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.

like image 45
Mahavir Avatar answered Mar 04 '23 22:03

Mahavir