JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old September 20th, 2006, 03:31 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 4
JS equivalent to php include file

I have tried it using php ie include 'somefile.js'; in the header, however it doesn't work. I was wondering if there's a javascript way of doing it so the file could be called in between the javascript tags in the header. the js data I have to put in another file are a load of vars etc.
ie:
<script type="text/javascript" language="javascript">
var blah blah
....................
function blah blah
</script>

Reply With Quote
  #2  
Old September 20th, 2006, 06:36 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information
 
Join Date: Sep 2005
Posts: 622 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 22 h 40 m 30 sec
Reputation Power: 3
I think there is no real equivalent. As an alternative way you could look at this link.

Reply With Quote
  #3  
Old September 20th, 2006, 08:40 AM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 542 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 2 h 58 m 28 sec
Reputation Power: 3
inc vars

As long as you reference the vars before you need them, they should be available for subsequent scripts. eg.
inc_test.html
HTML Code:
Original - HTML Code
    <html> <head> <script type="text/javascript" src="vars.js"></script> </head> <body> Hi, <script type="text/javascript" src="header.js"></script> <br /> Blah, blah, blah. Ipsom lorem abacadabra. <br /> <script type="text/javascript" src="footer.js"></script> </body> </html>

vars.js
JAVASCRIPT Code:
Original - JAVASCRIPT Code
  1. var name = "SnapCracker"; var aloha = "So long.";

header.js
JAVASCRIPT Code:
Original - JAVASCRIPT Code
  1. document.write(name);

footer.js
JAVASCRIPT Code:
Original - JAVASCRIPT Code
  1. document.write(aloha);


EDIT :lol: I just checked out the link Icon posted. Very good!

Last edited by Mittineague : September 20th, 2006 at 09:38 AM.

Reply With Quote
  #4  
Old September 21st, 2006, 04:26 AM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 4
It works!

Thanks Mittineague!

It was just the header info that I was concerned about as the my files which used the same js var were all 'top heavy' if you see what I mean, and now, if there are any changes to be made, I can do it in just one file. Life changing stuff! It's made a big difference. As mentioned before, I was trying to do the same thing before in php, without much success. And, well, thanks Icon for that link, I haven't had time to read in between the lines as yet, I don't get the joke, but I'm sure testing out js includes are humourous!

Reply With Quote
  #5  
Old September 21st, 2006, 07:20 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information
 
Join Date: Sep 2005
Posts: 622 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 22 h 40 m 30 sec
Reputation Power: 3
The article shows some methods, including Mittineagues method I think.

Last edited by Icon : September 21st, 2006 at 07:23 AM. Reason: - Misunderstood something, post was superfluous -

Reply With Quote
  #6  
Old September 21st, 2006, 01:17 PM
SnapCracker's Avatar
SnapCracker SnapCracker is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Kent, United Kingdom
Posts: 165 SnapCracker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 21 h 22 m 31 sec
Reputation Power: 4
Random include

Yeh thanks for that link. I had a chance to read some it. I like the random include which is useful for a selection of advertising banners on my site.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > JS equivalent to php include file


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 | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway