Closed Thread Icon

Preserved Topic: Reading values from a url? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18454" title="Pages that link to Preserved Topic: Reading values from a url? (Page 1 of 1)" rel="nofollow" >Preserved Topic: Reading values from a url? <span class="small">(Page 1 of 1)</span>\

 
Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-14-2001 21:23

Is it possible for Javascript to read values from a url like this:
htp://whatever.com/file.html?var=val

It seems like such a simple thing to do but I can't seem to find it.

Edit:

Ok, I've managed to well... kinda do it. But it's dogey....

code:
flag = (location.search)? 1:0
function contChk() {
if (flag) {
re = /[?]([A-Za-z0-9]+)/
str = location.search
area = str.replace(re, "$1")
top.content.location = area + ".html"
flag = 0
}
}



I'm using this to specify the target of a frame in the url to the HTML file containing the frameset.

So, whatever.com/index.html?news would load the news.html into the frame named 'content'. I know this seems kinda pointless but it does have it's uses.

I still think there'd be an easier way to read values from a url but for some reason I just can't find it!

[This message has been edited by Dracusis (edited 10-14-2001).]

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-15-2001 00:07

Yeah, location.search will return the string "?news". If you know the string will be as simple as that, you can simply run a test:

if (location.search.indexOf("news") != -1)
{
// load news
}

If there may be more complicated things, like "?news=yes&chocolate=good" then you may have to do some more complicated things. You can do them with regular expressions or with the indexOf function.

Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-15-2001 05:25

Cool, I didn't know about .indexOf, I'll have to play around with this...

Thanks Slime.

lallous
Paranoid (IV) Inmate

From: Lebanon
Insane since: May 2001

posted posted 10-15-2001 08:16
code:
if (location.search.match(/\?(.+)/))
top.content.location = RegExp.$1 + ".html";



You can tighten your code a bit like the above.

« BackwardsOnwards »

Show Forum Drop Down Menu