473,472 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

src="xyz.js?id=123"

Hi,

can a .js file read a parameter into it from the HTML file?

this is the code to use in peoples HTML files, each member has their own id.

<!-- TopCounters Code START -->
<script language="JavaScript" src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>
the original pphlogger.js has this in it

/* -----------------------------------------------
POWER PHLOGGER - v.2.2.5
// ----------------------------------------------------------
// SETTINGS:
// here should be your username you received from www.topcounters.com
// Do not edit this file manually!! Use the one you got in your
// confirmation-email or the one from PowerPhlogger's settings
// section.
id = "johnsmith";
So I want id to be set from the parameter not in the file.
I thought you could parse the URL bar after the ? but the .js wont go into the URL bar.

Herc
--
If you bury your head in the sand then don't open your mouth.
www.TopCounters.com
Jul 23 '05 #1
6 2178
|-|erc wrote:
Hi,

can a .js file read a parameter into it from the HTML file?

this is the code to use in peoples HTML files, each member has their own id.

<!-- TopCounters Code START -->
<script language="JavaScript" src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>

The js expression "location.search.substring(1)" will yield the
String "id=johnsmith", it's a small step to further parse the
query string.
Mick

the original pphlogger.js has this in it

/* -----------------------------------------------
POWER PHLOGGER - v.2.2.5
// ----------------------------------------------------------
// SETTINGS:
// here should be your username you received from www.topcounters.com
// Do not edit this file manually!! Use the one you got in your
// confirmation-email or the one from PowerPhlogger's settings
// section.
id = "johnsmith";
So I want id to be set from the parameter not in the file.
I thought you could parse the URL bar after the ? but the .js wont go into the URL bar.

Herc
--
If you bury your head in the sand then don't open your mouth.
www.TopCounters.com

Jul 23 '05 #2
Ivo
"|-|erc" <go***@beauty.com>
can a .js file read a parameter into it from the HTML file?
this is the code to use in peoples HTML files, each member has their own id.
<script language="JavaScript" src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>
So I want id to be set from the parameter not in the file.
I thought you could parse the URL bar after the ? but the .js wont go into

the URL bar.

Parameters attached to the src of a js file are really only useful if the js
file is created on the fly by the server and different parameters result in
different files sent to the client. If you want, you can detect the
parameter with a bit of script like this:
var s=document.scripts[0].src;
s=s.substr(s.indexOf('?')+1);
but this doesn't seem very efficient, when you can more easily do:
<script type="text/javascript"> var id='johnsmith'; </script>
<script type="text/javascript" src="blabla.js"></script>

HTH
Ivo
Jul 23 '05 #3
Lee
Mick White said:

|-|erc wrote:
Hi,

can a .js file read a parameter into it from the HTML file?

this is the code to use in peoples HTML files, each member has their own id.

<!-- TopCounters Code START -->
<script language="JavaScript"
src="http://www.topcounters.com/pphlogger.js?id=johnsmith"> </script>


The js expression "location.search.substring(1)" will yield the
String "id=johnsmith", it's a small step to further parse the
query string.


location.search will refer to the query of the current page,
not the value in the URL of the .js file.

The simplest solution would seem to be:

<script type="text/javascript">id="johnsmith"</script>
<script type="text/javascript"
src="http://www.topcounters.com/pphlogger.js?></script>

Since all of the script is executed in the current page, the
code in pphlogger.js can see global variables in this page.

Jul 23 '05 #4
JRS: In article <40*********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Sat, 17 Jul 2004
15:59:14 :

Parameters attached to the src of a js file are really only useful if the js
file is created on the fly by the server and different parameters result in
different files sent to the client.


They can also be used to pass parameters between successive pages on one
site.

Page 1
<br><a href="page3.htm?a>link a</a>
<br><a href="page3.htm?b>link b</a>

Page 2
<br><a href="page3.htm?A>link A</a>
<br><a href="page3.htm?B>link B</a>

Then script in page 3 can determine whether it was called (probably)
from A or a or B or B.
Each of my normal pages, e.g. itself.htm can frame itself by being
clicked on <a href="frames-4.htm?itself.htm">Frame This</a> (even if
already framed!).

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #5
Oh Strong One,
So I want id to be set from the parameter not in the file.
I thought you could parse the URL bar after the ? but the
.js wont go into the URL bar.
That isn't easy. The best way is to id the script DURING ONLOAD and
extract the url:

<script
id="example"
type="text/javascript"
src="http://www.example.com/script.js?prop1=value1"

</script>

..
..
..

window.onload = function() {
var urlForScript = document.getElementById("example").src;
/*
* Parse urlForScript with a Reg Exp
* or other String Function
*/
};

Make sure you don't try to execute that before the page has loaded,
otherwise you might get an error or even "undefined" for src! Hope
that helps.

--
Jimmy Cerra
Jul 23 '05 #6
"Dr John Stockton" <sp**@merlyn.demon.co.uk> wrote in
JRS: In article <40*********************@news.wanadoo.nl>, seen in
news:comp.lang.javascript, Ivo <no@thank.you> posted at Sat, 17 Jul 2004
15:59:14 :

Parameters attached to the src of a js file are really only useful if the js
file is created on the fly by the server and different parameters result in
different files sent to the client.


They can also be used to pass parameters between successive pages on one
site.

Page 1
<br><a href="page3.htm?a>link a</a>
<br><a href="page3.htm?b>link b</a>

Page 2
<br><a href="page3.htm?A>link A</a>
<br><a href="page3.htm?B>link B</a>

Then script in page 3 can determine whether it was called (probably)
from A or a or B or B.
Each of my normal pages, e.g. itself.htm can frame itself by being
clicked on <a href="frames-4.htm?itself.htm">Frame This</a> (even if
already framed!).


that's pretty standard if it goes into the URL bar, but loading .js is done
in the background.

if you want to see some *really* advanced throwing parameters around,
check how I converted a PHP chat script into a live chess tournament server.
www.chessit.com (swap to black if you have to then drag and drop a chessman).

thanks all the topcounters HTML is running now.

Herc

Jul 23 '05 #7

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

Similar topics

15
by: Gérard Talbot | last post by:
Hello all, I'd like to know and understand the difference between, say, <img src="/ImageFilename.png" width="123" height="456" alt=""> and <img src="/ImageFilename.png" style="width:...
5
by: Craig Keightley | last post by:
Please help, i have attached my page which worksin IE but i cannnot get the drop down menu to fucntion in firefox. Any one have any ideas why? Many Thanks Craig ...
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
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,...
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
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...
0
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...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.