JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 1st, 2001, 10:59 AM
blaz blaz is offline
Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: Ljubljana, Slovenia, Europe
Posts: 29 blaz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
JavaScript without HEAD

Is it possible to write JavaScript code without inserting fuctions into HEAD part of the page?

I generate my pages dinamicly. In PHP a always use the same file to generate header of the page. How can I then use JavaScript if I can't have JavaScript code in the HEAD section of generated HTML?

I really have no idea about JavaScript, sorry.

Blaz

Reply With Quote
  #2  
Old October 1st, 2001, 11:05 AM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 52 sec
Reputation Power: 13
Hi!

<script> blocks are allowed within <body> and </body>. Code in one of those blocks that is not encapsulated in functions is immediately executed after being loaded in the browser. So you can use functions here as well.

Atrus.
__________________
Webmaster - Stefan Meier KG TABAKWAREN - Pfeifen, Premium-Zigarren, ... (_Ger)

Reply With Quote
  #3  
Old October 1st, 2001, 04:47 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
HTML event handlers (onClick,onMouseover, etc.) are JavaScript (so, of course, is the javascript: url) and are found in the <body> of the document. You can reference functions in them, but also embed the JS right in the HTML.

You can also do this:

<body>
<table>
......etc.
</table>
<div>content</div>

<script language="JavaScript" type="text/javascript" src="myScript.js">

<....more markup...

where myScript.js is an external JavaScript file with nothing but JS in it. It will be written into the HTML stream right where it appears, as if it was hardcoded there. More...

Reply With Quote
  #4  
Old October 2nd, 2001, 09:10 AM
Atrus's Avatar
Atrus Atrus is offline
yet another member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2001
Posts: 262 Atrus User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 52 sec
Reputation Power: 13
Hi Adios!

Thanks for your post, I did not know that, yet! Would you confirm one other thing?! I've seen this before and it works, but is it valid, too? Simply having JS block within the body?

<body>
<table>
......etc.
</table>
<div>content</div>

<script language="JavaScript" type="text/javascript">

<!--
function doingStuff { etc.....}
var hello = "Hello World";
document.println(hello);
//-->

</script>

<....more markup...

Reply With Quote
  #5  
Old October 2nd, 2001, 10:18 PM
adios adios is offline
Senior Citizen
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2001
Location: leftcoast
Posts: 2,019 adios User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 15
Yes.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > JavaScript without HEAD

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap