View Full Version : Resolved Var: Get URL
Hello Everyone!
I have a kinda complicated problem. I need a way to call part of the URL of a page (in a var). For example, if the URL was 'http://www.mydomain.com/video.html?item=3' i would like to call only the '3' part. However, (the complicated part) the number at the end could be several digits (they're all different). Does anyone know how to do this? Feel free to ask questions.
Is it possible you could use PHP? Or is Javascript a must?
can't you just use the split method in javascript?
var item = url.split("item=");
item is now an array and then you can use item[1] (this is 3)
@Nile
Sorry, it has to be JavaScript.
------------------------------------------------------------
@NDK
So, your saying i could place 'var item = url.split("item=");'. Then, I could call it with 'item' where i need it, right?
I just tried it, and it said 'undefined'.
I did the test yesterday and it worked...
this was my test:
<script type="text/javascript">
var url = "http://www.mydomain.com/video.html?item=3"
var item = url.split("item=");
document.write(item[1]);
</script>
result = 3
item is the array, item[0] is everything before item=, item[1] is everything after item=
So if you have an url like "http://www.mydomain.com/video.html?item=3&node=5", you'll need to use a second split to have only 3 as result
code:
<script type="text/javascript">
var url = "http://www.mydomain.com/video.html?item=3&node=5"
var item = url.split("item=");
var newItem = item[1].split("&");
document.write(newItem[0]);
</script>
That's great and all, really it is. however, there's still a little problem. if i write 'var url = "http://www.mydomain.com/video.html?item=3"', it will always write 3, even if the item really is 7. I want the script to call it from the acually url.
Schmoopy
09-18-2009, 03:25 PM
There you go.
<script type="text/javascript">
var url = document.location.href;
var item = url.split("item=");
document.write(item[1]);
</script>
thank you so much. however, i still have one more problem. when i call it, it places a comma before the the number. why is that?
Never mind... I got it! Thank you all so much!
Glad to help.
It seems your topic is solved... Please set the status to resolved.. To do this:
Go to your first post ->
Edit your first post ->
Click "Go Advanced" ->
Then in the drop down next to the title, select "RESOLVED"
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.