473,385 Members | 1,610 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,385 software developers and data experts.

Obtaining query_string from JavaScript

Hi All,

Let's say we have site index.html with JS embedded there in this
way:

<script type="text/javascript" src="my_script.js?username=mr_bean"></
script>

Question:
How to get access to "username" query string constant directly from
my_script.js file ? "location.search" is no option here because it
will access index.html's QUERY STRING not my_script.js's. Any idea ?

Best regards,
Marcin Zduniak
Sep 24 '08 #1
4 1884
SAM
Le 9/24/08 5:15 PM, Marcin a écrit :
Hi All,

Let's say we have site index.html with JS embedded there in this
way:

<script type="text/javascript" src="my_script.js?username=mr_bean"></
script>
funny idea, no ?
Question:
How to get access to "username" query string constant directly from
my_script.js file ? "location.search" is no option here because it
will access index.html's QUERY STRING not my_script.js's. Any idea ?
var S = document.getElementsByTagName('script');
for(var i=0, n=S.length; i<n; i++)
if(S[i].src.toString().indexOf('my_script') >=0) {
alert('var = '+S[i].src.toString().split('=')[1]);
break;
}
--
sm
Sep 24 '08 #2
Marcin wrote:
Let's say we have site index.html with JS embedded there in this
way:

<script type="text/javascript" src="my_script.js?username=mr_bean"></
script>

Question:p
How to get access to "username" query string constant directly from
my_script.js file ? "location.search" is no option here because it
will access index.html's QUERY STRING not my_script.js's. Any idea ?
The script cannot "know" how it is included. However, you can use a
server-side script to generate a client-side one, and the former can
read the query part of the request URI.

For example, in my_script.js.php (I would use Content Negotiation to get
rid of the security-relevant `.php' in the URI):

var username = "<?php echo addslashes($_REQUEST['username']); ?>";
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 26 '08 #3
On 2008-09-26 20:24, Thomas 'PointedEars' Lahn wrote:
For example, in my_script.js.php (I would use Content Negotiation to get
rid of the security-relevant `.php' in the URI):
I wouldn't. I suppose content negotiation could also be (mis)used to
hide an extension, but it was really intended to serve alternate
representations of resources depending on the UA's capabilities and
preferences (different languages or media types). See RFC 2616.
URL rewriting would be more appropriate to hide or change file names.

- Conrad
Sep 26 '08 #4
Conrad Lender wrote:
On 2008-09-26 20:24, Thomas 'PointedEars' Lahn wrote:
>For example, in my_script.js.php (I would use Content Negotiation to get
rid of the security-relevant `.php' in the URI):

I wouldn't. I suppose content negotiation could also be (mis)used to
hide an extension, but it was really intended to serve alternate
representations of resources depending on the UA's capabilities and
preferences (different languages or media types). See RFC 2616.
URL rewriting would be more appropriate to hide or change file names.
URL rewriting cannot be reasonably applied to this problem: you would have
to write expressions for each script file (and have PHP parse all, which is
inefficient), or write an expression for all directories where you have to
keep all your generated script files (which is inflexible).

I might add that He who invented the Web and those who largely implemented
it disagree with you about the use of content negotiation as I do:

<http://www.w3.org/Provider/Style/URI>
<http://httpd.apache.org/docs/2.0/content-negotiation.html#naming>
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Sep 26 '08 #5

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

Similar topics

3
by: Phil Powell | last post by:
Has anyone here ever done a case where you have a select multiple form element and you have to do both server-side and client-side validation? I am honestly not sure how to do it in Javascript (I...
5
by: PhilM | last post by:
Could someone give me the topics to look up on php.net, to be able to work out how to remove stuff added to a query_string? I wish to check $QUERY_STRING, and remove any user added extras. TIA...
3
by: Gilbert Saint-Flour | last post by:
Hello: I have this one line of PHP code which I'd like to convert to Javascript. The PHP code conditionally issues a BASE statement when the html page is called with a frame name, e.g....
7
by: Privacy Advocate | last post by:
//crossposted to: comp.lang.javascript, alt.comp.lang.javascript in an effort to get factual answers from JavaScript experts// Simply put; Is it possible to obtain the real (actual) IP address of...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
25
by: wd | last post by:
I want my server to send a 404 header if a URL with a query string is requested. So if a browser or spider requests something like www. my_site .com?p=chair they would get a 404... But if they...
3
by: keith.schincke | last post by:
I know I must be missing something basic. I am developing of Firefox 1.5 and am trying to to send a basic QUERY_STRING to a test CGI that will print the data back to the brower: I can print my...
4
by: benwylie | last post by:
I am running IIS 6.0 on Windows 2003. I would like to be able to run a perl script from a web page and include the output. I have tried doing it with an ssi: <form action='docsearch.shtml'...
6
by: honguin | last post by:
Hi, The current scenario is that I have an iframe inside an asp.net web page where I periodically check the url inside the iFrame. I know that all this information can be obtained in the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
0
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...

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.