Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Where to put code when access to the <HEAD> tag isn't available! 3

Status
Not open for further replies.

prover

Programmer
Sep 12, 2001
54
US
Hello,

Our company has split our web pages into two include files. A header and footer include files. Because of this I no longer have "access" to the <HEAD> tags to place my javascript code.

I was wondering if my js code should go above the ssi or below it? Or does it really matter?

above:

<script src="jsfunctions.js">
<!-- #include virtual="header.inc" -->
main body here
<!-- #include virtual="foot.inc" -->

below:

<!-- #include virtual="header.inc" -->
<script src="jsfunctions.js">
main body here
<!-- #include virtual="foot.inc" -->


TIA!!!
 
ur <script> tag can go anywhere on the page. even this is o.k:
<table>
<tr><td>asdasd<script>alert('asd')</script></td>....


as long as u open it and close it, it will work, it is better to place it in head tag so that all variables are already initialised and read when the page loads...

Known is handfull, Unknown is worldfull
 
vbkris said:
so that all variables are already initialised and read when the page loads

As far as I'm aware, all variables, etc will be initialised before the page loads, regardless of where the script tags are located.

Hope this helps,
Dan
 
If <head> is not available, place it as closer to the top as possible. Some dirty constructs like this:
Code:
<html>
<head>
<head>
<body>
<h1><script type="text/javascript"> document.write( blah() ); </script></h1>

<script type="text/javascript">
function blah(){	return ("something"); }
</script>

</body>
</html>
... may not work.
 
>>As far as I'm aware, all variables, etc will be initialised before the page loads, regardless of where the script tags are located.

maybe i wasnt clear, i meant that for functions (which will be called in the body). anyway what other reason could be there???

Known is handfull, Unknown is worldfull
 
Thanks for the feed-back!

So as long as my functions come before any calls to them I should be ok.

I'm curious if there are any drawbacks (other than non-initialized variables) to not having my code between the head tags. Poor performance etc. ???

Just curious. I'm a newbee when it comes to javascript.

Never argue with an idiot. He'll just drag you to his level and beat you with experience!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top