[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Is it any fifference where I put the script tag in this example

Tony Johansson

2/23/2015 11:10:00 PM

Hello!

Just assume that I have a very simple script tag that looks like this
<script>
document.write("This is a test");
</script>

Then is it just the equivalent if I put this script tag within header tag or
within the body tag.

//Tony

4 Answers

Christoph M. Becker

2/23/2015 11:25:00 PM

0

Tony Johansson wrote:

> Just assume that I have a very simple script tag that looks like this
> <script>
> document.write("This is a test");
> </script>
>
> Then is it just the equivalent if I put this script tag within header
> tag or within the body tag.

I suggest you try it out. You'll notice the difference quickly.

BTW: it is not a script *tag*, but rather a script *element*.

--
Christoph M. Becker

Tony Johansson

2/23/2015 11:30:00 PM

0

Forget the question!

//Tony

"Tony Johansson" <johansson.andersson@telia.com> skrev i meddelandet
news:mcgbvo$45v$1@dont-email.me...
> Hello!
>
> Just assume that I have a very simple script tag that looks like this
> <script>
> document.write("This is a test");
> </script>
>
> Then is it just the equivalent if I put this script tag within header tag
> or within the body tag.
>
> //Tony

Denis McMahon

2/24/2015 12:09:00 AM

0

On Tue, 24 Feb 2015 00:09:41 +0100, Tony Johansson wrote:

> Just assume that I have a very simple script tag that looks like this
> <script>
> document.write("This is a test");
> </script>

> Then is it just the equivalent if I put this script tag within header
> tag or within the body tag.

No.

This particular script element will write the text "This is a test" into
the document at the point you insert the script tag.

--
Denis McMahon, denismfmcmahon@gmail.com

JJ

2/24/2015 1:46:00 PM

0

On Tue, 24 Feb 2015 00:09:21 +0000 (UTC), Denis McMahon wrote:
> On Tue, 24 Feb 2015 00:09:41 +0100, Tony Johansson wrote:
>
>> Just assume that I have a very simple script tag that looks like this
>> <script>
>> document.write("This is a test");
>> </script>
>
>> Then is it just the equivalent if I put this script tag within header
>> tag or within the body tag.
>
> No.
>
> This particular script element will write the text "This is a test" into
> the document at the point you insert the script tag.

And then be moved into the document body if the script element is within the
document head. Interestingly, how this is exactly done, varies accross
different browser engines.