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

Parsing Requesting URL in javascript?

I have the following request URL in an ASPx page:

http://crm/custom/fileviewer/default.aspx?NAME

I want to be able to parse the requesting URL and pass NAME into a
variable.

Can anyone give me the code to do this?

Cheers
Tim

Aug 20 '07 #1
3 3594
wrote on 20 aug 2007 in comp.lang.javascript:
I have the following request URL in an ASPx page:

http://crm/custom/fileviewer/default.aspx?NAME

I want to be able to parse the requesting URL and pass NAME into a
variable.

Can anyone give me the code to do this?
Not "the" code as there are a miriad of ways:

I give you the clientside string manipulation.

<script type='text/javascript'>

var s = 'http://crm/custom/fileviewer/default.aspx?NAME';

var r = s.split('?')[1]
alert(r)

// or:

r = s.replace(/[^\?]*\?/,'')
alert(r)

</script>
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Aug 20 '07 #2
I wrote this a few days ago:

It parses query strings, example at bottom

parseQuery = function() {
window.query = {};
var qstr = location.search.substr(1).split('&');
var qstr_len = qstr.length;
for(var i=0; i < qstr_len; i++) {
var q = (qstr[i] ? qstr[i].split('=') : []);
if(q.length) {
firstBracket = q[0].indexOf('[');
if(firstBracket != -1 && -1 != (secondBracket = q[0].indexOf(']',
firstBracket))) {
var queryString = q[0].substr(0, firstBracket);
window.query[queryString] = window.query[queryString] || [];
if(firstBracket+1 == secondBracket) {
window.query[queryString].push(q[1]);
} else {
queryIndex = q[0].substr(firstBracket+1, (secondBracket-
(firstBracket+1)));
window.query[queryString][queryIndex] = q[1];
}
} else {
window.query[q[0]] = q[1];
}
}
}
window['$_GET'] = window.query;
}

/**
Example:

URL: http://example.com/?aff=raja&c[]=1&x[cool]=2
>>parseQuery()
>>window.query['c'][0]
"1"
>>window.query['aff']
"raja"
>>window.query['x']['cool']
"2"
**/
On Aug 20, 9:12 am, timchi...@gmail.com wrote:
I have the following request URL in an ASPx page:

http://crm/custom/fileviewer/default.aspx?NAME

I want to be able to parse the requesting URL and pass NAME into a
variable.

Can anyone give me the code to do this?

Cheers
Tim

Aug 20 '07 #3
Just to clarify, the function above reads the current URL of the page
and parses the query strings into window.query

On Aug 20, 1:12 pm, aonic <raja.ka...@gmail.comwrote:
I wrote this a few days ago:

It parses query strings, example at bottom

parseQuery = function() {
window.query = {};
var qstr = location.search.substr(1).split('&');
var qstr_len = qstr.length;
for(var i=0; i < qstr_len; i++) {
var q = (qstr[i] ? qstr[i].split('=') : []);
if(q.length) {
firstBracket = q[0].indexOf('[');
if(firstBracket != -1 && -1 != (secondBracket = q[0].indexOf(']',
firstBracket))) {
var queryString = q[0].substr(0, firstBracket);
window.query[queryString] = window.query[queryString] || [];
if(firstBracket+1 == secondBracket) {
window.query[queryString].push(q[1]);
} else {
queryIndex = q[0].substr(firstBracket+1, (secondBracket-
(firstBracket+1)));
window.query[queryString][queryIndex] = q[1];
}
} else {
window.query[q[0]] = q[1];
}
}
}
window['$_GET'] = window.query;

}

/**
Example:

URL:http://example.com/?aff=raja&c[]=1&x[cool]=2
>parseQuery()
window.query['c'][0]

"1"
>window.query['aff']

"raja"
>window.query['x']['cool']

"2"
**/

On Aug 20, 9:12 am, timchi...@gmail.com wrote:
I have the following request URL in an ASPx page:
http://crm/custom/fileviewer/default.aspx?NAME
I want to be able to parse the requesting URL and pass NAME into a
variable.
Can anyone give me the code to do this?
Cheers
Tim

Aug 20 '07 #4

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

Similar topics

7
by: Eric Osman | last post by:
If my question sounds ill-formed, please cut me some slack as I'm just getting started with this part of the code. We're trying to do an axis soap interface, that is, talk to a site that already...
51
by: Paul Gorodyansky | last post by:
Hi, Ran into the following problem while trying to have a code to attach a Virtual Keyboard to any user's form: User clicks a button and my JavaScript changes outerHTML of say <textarea -...
11
by: vunet.us | last post by:
Since XMLHTTP Request does not support loading of XML from other servers, I decided to use a trick: load XML into hidden iframe and then get that XML with JavaScript to parse. But, is this a good...
0
by: abdulbasith | last post by:
if any machine is requesting a webpage ,i need to find out the ip address of the requesting machine using javascript in asp.net. can anyone guide me in doing that. i did the below code, but it...
0
by: Arun dudee | last post by:
I want to make an webpage.In which content will be coming from xml file. can any one tell me how to display an using file lcation from xml file.as we have img attribute in html then how to...
7
by: ArdGre | last post by:
HI THERE, I have a strange problem. I am writing a firefox extension to the Onlywire API (http://onlywire.com/index?api). Now the problem is when I tag pages using the onlywire API the service...
3
by: raghudr | last post by:
Hi all, I am parsing a .xml file.My main intention is to retrieve the name value of node "Signal":- "Name Value" which is "rag". i want to store only the <signal"name value" that is only...
1
by: Philip Semanchuk | last post by:
On Oct 12, 2008, at 5:25 AM, S.Selvam Siva wrote: Selvam, You can try to find them yourself using string parsing, but that's difficult. The closer you want to get to "perfect" at finding URLs...
0
by: atencorps | last post by:
Hello I have the following code but need some help on it. The idea of the code is the main sections ie Service Management are viewable when the page is loaded and by clicking on the main...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.