473,399 Members | 3,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Client-side includes with JavaScript

I'm trying to simulate server-side includes on the client-side by
using JavaScript. My main problem is this: is there a way to somehow
pass a variable into a directive like this:

<SCRIPT LANGUAGE="JavaScript" type="text/javascript"
src="$myPageVar$"></SCRIPT>
....where $myPageVar$ is a variable I've declared, and somehow,
magically, its value gets put into this directive? The only way I can
get this to work is if I hard-code a value for $myPageVar$ in the
following way:

<SCRIPT LANGUAGE="JavaScript" type="text/javascript"
src="homeInc.js"></SCRIPT>
....which is of limited use. Is there a way for me to use variables in
such a directive? Or is there a better way to be doing client-side
includes?

Thanks.
Jul 20 '05 #1
10 3375
In article <85*************************@posting.google.com> ,
gr**@ZeroG.com enlightened us with...
I'm trying to simulate server-side includes on the client-side by
using JavaScript. My main problem is this: is there a way to somehow
pass a variable into a directive like this:

<SCRIPT LANGUAGE="JavaScript" type="text/javascript"
src="$myPageVar$"></SCRIPT>


This worked in IE...(put your file name where mine is for myVar)

<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> New Document </title>
<script>
myVar = "jsCaptureEnterKey.js";
document.write("<s"+"cript src='"+myVar+"'></s"+"cript>");
</script>
</head>

<body>
hi
</body>
</html>
-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2
> <html>
<head>
<title> New Document </title>
<script>
myVar = "jsCaptureEnterKey.js";
document.write("<s"+"cript src='"+myVar+"'></s"+"cript>");
</script>
</head>


The trick with writing script tags is that browsers get confused by scripts
containing "</" in theory and "</script>" in practice. The line above fails the
in theory case. Try this instead:

document.write('<script src="' + myVar + '"><\/script>');

Putting spaces around the plus signs make it much easier to read.

http://www.crockford.com/#javascript
Jul 20 '05 #3
kaeli <in********************@NOSPAMatt.net> writes:
In article <85*************************@posting.google.com> ,
gr**@ZeroG.com enlightened us with...
<SCRIPT LANGUAGE="JavaScript" type="text/javascript"
src="$myPageVar$"></SCRIPT>


This worked in IE...(put your file name where mine is for myVar)


Yes, the trick is to document.write the script tag with your
variables in place. (scripts of more scripts!).
<script>
<script type="text/javascript">

Just for being pedantic, the type attribute is mandatory in HTML 4,
and you did add the DOCTYPE (a bad DOCTYPE that puts browsers into
quirks mode, though, but that's another rant).
myVar = "jsCaptureEnterKey.js";
document.write("<s"+"cript src='"+myVar+"'></s"+"cript>");


Just write it as
document.write("<script src='"+myVar+"'><\/script>");

You don't need to split "script". The one thing that a script is not
allowed to contain (according to specification) is the sequence "</".
In practice, browsers allow that, and only ends the script tag at
"</script>". In either case, just one backslash is sufficient.

/L 'Just needed to say that!'
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
In article <wu**********@hotpop.com>, lr*@hotpop.com enlightened us
with...

Just for being pedantic, the type attribute is mandatory in HTML 4,
and you did add the DOCTYPE (a bad DOCTYPE that puts browsers into
quirks mode, though, but that's another rant).


Please explain.
My html editor sticks that in, and I can change it, so if it's a bad
one, I'd like to know about it.

Thanks for the tips, both of you who replied.

-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #5
JRS: In article <wu**********@hotpop.com>, seen in
news:comp.lang.javascript, Lasse Reichstein Nielsen <lr*@hotpop.com>
posted at Thu, 14 Aug 2003 23:19:37 :-

You don't need to split "script". The one thing that a script is not
allowed to contain (according to specification) is the sequence "</".
In practice, browsers allow that, and only ends the script tag at
"</script>". In either case, just one backslash is sufficient.


However, W3's TIDY, in checking mode, will give

Warning: '<' + '/' + letter not allowed here

for </bbb> in a test page containing

<script>
S = '</bbb>'
</script>

and it is useful to get a warning-free test even if the tester may be
over-strict.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/JS/&c., FAQ topics, links.
Jul 20 '05 #6
> >You don't need to split "script". The one thing that a script is not
allowed to contain (according to specification) is the sequence "</".
In practice, browsers allow that, and only ends the script tag at
"</script>". In either case, just one backslash is sufficient.


However, W3's TIDY, in checking mode, will give

Warning: '<' + '/' + letter not allowed here

for </bbb> in a test page containing

<script>
S = '</bbb>'
</script>

and it is useful to get a warning-free test even if the tester may be
over-strict.


jslint also checks for this.

http://www.crockford.com/javascript/lint.html

Jul 20 '05 #7
kaeli <in********************@NOSPAMatt.net> writes:

[DOCTYPE]
Please explain.
My html editor sticks that in, and I can change it, so if it's a bad
one, I'd like to know about it.


Opera has an explanation of the DOCTYPE switching
<URL:http://www.opera.com/docs/specs/doctype/>
It behaves the same as IE and almost the same as Mozilla, and there
are also links to Microsoft and Mozilla pages on the same subject.

The short summary is that some DOCTYPEs puts browsers into
backwards compatability mode, where they emulate the bugs of IE4
(because a lot of pages were written for that browser and fails
completely in a purely standards compliant browser). New pages
should not be created for to backwards compatible mode, but to
standards mode.

Your DOCTYPE was for HTML 4.01 Transitional and with no URL, which
triggers quirks mode in all three browsers.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #8
In article <vf**********@hotpop.com>, lr*@hotpop.com enlightened us
with...

Your DOCTYPE was for HTML 4.01 Transitional and with no URL, which
triggers quirks mode in all three browsers.


That is VERY useful to know.

Is it better to omit the doctype or should I use the proper one?
-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #9
kaeli <in********************@NOSPAMatt.net> writes:
Is it better to omit the doctype or should I use the proper one?


Use a proper one. Omitting a doctype also triggers quirks mode.
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #10
In article <oe**********@hotpop.com>, lr*@hotpop.com enlightened us
with...
kaeli <in********************@NOSPAMatt.net> writes:
Is it better to omit the doctype or should I use the proper one?


Use a proper one. Omitting a doctype also triggers quirks mode.
/L


Excellent. Thanks for all the help!

--
-------------------------------------------------
~kaeli~
Why do people who know the least know it the loudest?
If that cell phone was up your a$$, maybe you could
drive a little better!
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
0
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and...
8
by: Ankit Aneja | last post by:
i am doing here some some socket-client work in C# windows service it is working fine for multiple clients now i want to limit these multiple clients to 25 for example i want that when service...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
14
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.