473,800 Members | 2,342 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query String from src

Hello,

I was wondering if you can get the info from the query string in a
server-side javascript tag?

Here's what I'm trying to do
In the head of page A
....
<script language="JavaS cript" src="script.js? id=test</script>
....
And in my script.js file
....
getArgs();

function getArgs() {
var args = new Object();
var query = location.search .substring(1);
var pairs = query.split('&' );
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('='); "name=value ".
if (pos == -1) continue;.
var argname = pairs[i].substring(0,po s);
var value = pairs[i].substring(pos+ 1);
args[argname] = unescape(value) ;
}
alert (args.id);
}
....

I get the alert, but is displays "undefined" .

Can this be done?

Thanks,

dstefani
Jul 23 '05 #1
8 2188
On Sat, 15 May 2004 12:06:50 GMT, dstefani wrote:
I was wondering if you can get the info from the query string in a
server-side javascript tag?
Yes. (*server-side*?? No.
But I don'y think you mean that)
Here's what I'm trying to do


Here is a (bad) example with some good
links to threads with tips right here..
<http://www.physci.org/test/003url/index.html?url= http://mybiz.com/&when=now>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #2
I think I need to clarify...

I would like to know if this is possible...
Sending a query string from this tag:

<script language="JavaS cript" src="script.js? id=test"</script>

Can the src script recognize the query string?
I can do it perfectly with an <a href="page.html ?id=test">, but I can't
get it to work as noted in the src="script.js? id=test"
Here is whats in my js script, it works fine for a link.

Thanks,

dstefani

getArgs();

function getArgs() {
var args = new Object();
var query = location.search .substring(1);
var pairs = query.split('&' );
for(var i = 0; i < pairs.length; i++) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i].substring(0,po s);
var value = pairs[i].substring(pos+ 1);
args[argname] = unescape(value) ;property.
}
alert (args.id);
}
Jul 23 '05 #3
On Sat, 15 May 2004 14:52:58 GMT, dstefani wrote:
I think I need to clarify...
Spot on there. ;-)
I would like to know if this is possible...
Sending a query string from this tag:

<script language="JavaS cript" src="script.js? id=test"</script>
Firstly, it is missing a '>' character..
<script language="JavaS cript" src="script.js? id=test"></script>
Can the src script recognize the query string?


OK, now...

What is it that you expect the script.js
file to *do* with the id=test?

If it requires the information, it can get
it from the URL (that your normal link
points to) as shown in the example I pointed to.

** But no, I do not believe there is a way
to hand information to a .js file as you
describe. **

Which leads us to an important question.
What are you actually trying to achieve?

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology
Jul 23 '05 #4
Andrew Thompson wrote:
On Sat, 15 May 2004 14:52:58 GMT, dstefani wrote: Firstly, it is missing a '>' character..
<script language="JavaS cript" src="script.js? id=test"></script> Which leads us to an important question.
What are you actually trying to achieve?


Thanks for your reply and time.

I am trying to track visitor movement through a site.

1/ use script.js to set a cookie
2/ grab the querystring in the afore mentioned tag to know which site it
is. I guess I could have a lookup table that checked HTTP headers for
the location and mapped it to an account, but it would be easy if I
could get it from that tag.

-dstefani
Jul 23 '05 #5
Lee
dstefani said:

Hello,

I was wondering if you can get the info from the query string in a
server-side javascript tag?

Here's what I'm trying to do
In the head of page A
...
<script language="JavaS cript" src="script.js? id=test</script>
...
And in my script.js file
...
getArgs();

function getArgs() {
var args = new Object();
var query = location.search .substring(1);

You seem to misunderstand how that script block is loaded
and executed. There is nothing "server-side" about it.
The code is loaded into the current HTML page and executes
in that context, which means that location.search will
always refer to the URL of the current HTML page.

Jul 23 '05 #6
Lee wrote:
And in my script.js file
...
getArgs();

function getArgs() {
var args = new Object();
var query = location.search .substring(1);


You seem to misunderstand how that script block is loaded
and executed. There is nothing "server-side" about it.
The code is loaded into the current HTML page and executes
in that context, which means that location.search will
always refer to the URL of the current HTML page.


I knew my stupidity would come into play soon.
Can I change my function to recognize the query string in the scr=""
parameter?

- dstefani
Jul 23 '05 #7
Ivo
"dstefani" wrote
Andrew Thompson wrote:
On Sat, 15 May 2004 14:52:58 GMT, dstefani wrote:

Firstly, it is missing a '>' character..
<script language="JavaS cript" src="script.js? id=test"></script>


Secondly, the language attribute should be dropped and a type of
text/javascript be specified, so the resulting tag would be:

<script type="text/javascript" src="script.js? id=test"></script>

The location object is about the location of the page containing the script.
I don't think I 'm saying anything new. The source of the script itself is
document.script s[n].src in IE4+ and
document.getEle mentsByTagName( 'script')[n].src in some other browsers where
n is the index of the script. This is a string which can be parsed for
questions marks and equal signs.

The extension to the source file name may be .php or .asp or anything as
long as the file itself contains javascript and the server sends the
appropiate headers.

Sadly, a running script does not know from which file it came if there more
than one .js file in a page.
HTH
Ivo
Jul 23 '05 #8
Lee
dstefani said:

Lee wrote:
And in my script.js file
...
getArgs();

function getArgs() {
var args = new Object();
var query = location.search .substring(1);


You seem to misunderstand how that script block is loaded
and executed. There is nothing "server-side" about it.
The code is loaded into the current HTML page and executes
in that context, which means that location.search will
always refer to the URL of the current HTML page.


I knew my stupidity would come into play soon.
Can I change my function to recognize the query string in the scr=""
parameter?


That's just ignorance, not stupidity.
The fact that the code is executed in the context of the current
HTML page probably means that there's an easier way to do what
you're trying to accomplish. For example:

<script type="text/javascript">id= test</script>
<script type="text/javascript" src="script.js</script>
The value of id will be available to the code within script.js

Jul 23 '05 #9

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

Similar topics

8
8246
by: Phil Powell | last post by:
if (document.location.href.indexOf('?') >= 0) document.location.href = document.location.href.substring(0, document.location.href.indexOf('?')); if (document.location.href.indexOf('#') >= 0) { document.location.href = document.location.href.substring(0, document.location.href.indexOf('#')) + '?' + newUrl; } else { document.location.href = document.location.href + '?' + newUrl; }
3
7452
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script "text/javascript"> function getQueryVariable(variable) { var query = window.location.search.substring(1);
4
2861
by: Alan Lane | last post by:
Hello world: I'm including both code and examples of query output. I appologize if that makes this message longer than it should be. Anyway, I need to change the query below into a pivot table query. I'm having trouble doing it. Help! Here is my code so far: Sub OldRegionQuery()
0
3518
by: starace | last post by:
I have designed a form that has 5 different list boxes where the selections within each are used as criteria in building a dynamic query. Some boxes are set for multiple selections but these list boxes do not necessarily need to have a selection made to be used in the dynamic query. In essence the form can have selections made in all or none of its list boxes to form the dynamic query I am looking to get some feedback in reference to...
3
3304
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string values in it like... Between #12/1/2004# And #12/31/2004# - or - >= #6/10/2005# - or -
4
3045
by: deko | last post by:
When using OutputTo with a query, the 'File name' window in the 'Output To' dialog gets populated with the name of the query by default. This makes the exported file self-describing if the query is named on the fly. The benefit is consistent file naming, and users don't have to enter a file name when exporting. The problem is the query has to be renamed every time, and I don't know how to find it in the QueryDefs collection other than...
1
2711
by: Oliver Bleckmann | last post by:
Damn, what's wrong here? CGI cgi; map<string,stringcgiParam = cgi.analyseCgiParam(); cout << cgiParam << endl; cout << cgiParam << endl; /////////////////////// #include <iostream>
2
17653
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
How can I run this query against a table in my Access database? I don't know hwo to use it in C#. In VB I would use .Recordset = "some sql statement". How do I do this in C#? //I get a vlaue form a cell and apply it to the SQL statement commandCol = scriptDataGridView.FormattedValue.ToString(); string sCommand = "SELECT CommandString FROM Commands WHERE CommandName = " + commandCol; //This reutne a valie SQL statement which will return...
1
1967
by: TF | last post by:
This group came through for me last time so here we go again. My page shows paint colors, brand name, product code, etc in a gridview with the background matching the paint color. Several links on the page are used to call itself with querystring values for brand, thinner, finish, etc. The page must show all colors if the querystring is empty and filter out records that don't match the querystring value when it's not. I've tried building...
3
2563
by: pbd22 | last post by:
Hi. I need some help with structuring my query strings. I have a form with a search bar and some links. Each link is a search type (such as "community"). The HREF for the link's anchor looks like the following: <a href="?searchtype=2">Community</a>
0
9691
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
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10505
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
10035
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...
1
7580
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
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
5471
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...
1
4149
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
2945
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.