473,785 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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="JavaS cript" 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="JavaS cript" 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 3403
In article <85************ *************@p osting.google.c om>,
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="JavaS cript" 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 = "jsCaptureEnter Key.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 = "jsCaptureEnter Key.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************ ********@NOSPAM att.net> writes:
In article <85************ *************@p osting.google.c om>,
gr**@ZeroG.com enlightened us with...
<SCRIPT LANGUAGE="JavaS cript" 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 = "jsCaptureEnter Key.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**********@h otpop.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**********@h otpop.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.demo n.co.uk/js-index.htm> JS maths, dates, sources.
<URL:http://www.merlyn.demo n.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************ ********@NOSPAM att.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**********@h otpop.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************ ********@NOSPAM att.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

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

Similar topics

15
4491
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 computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
2
4673
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 Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is specified on a result set, no nested procedures can access the result set.
0
2169
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 can't see that I am doing anything wrong (i obviousely am though) everything "works", client connects to server and when anything is sent to the server it starts the mp3 and passes all messages the way i ment for it to except that my server is...
8
2747
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 starts objects for all these 25 clients are created and when client connects it should be accepted and will not allow more than 25 clients to connect and when client diconnects that object can be allocated to another client who requests i am not...
2
1992
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
4452
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
7578
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. Any help appreciated! The ordeal is a follows I am using Solaris 10 with php5.1.1. GCC:
0
1746
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 createSocketServer($host='192.168.1.34',$port=2222) { $max_clients = 10;
2
4103
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 server machine IP for client and server) please guide me? server : #include <winsock2.h> #include <iostream> #include <stdio.h> #include <string.h> #include <windows.h> #pragma comment(lib, "ws2_32");
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.