• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1537
  • Last Modified:

Get URL string...

Using javascript, how can I pull the last 6 digits from a url...

http://www.asfdjklasfd.com/card.html?x=123456


and put it into a variable...

Thanks
0
rJonesX
Asked:
rJonesX
1 Solution
 
ZvonkoSystems architectCommented:
Try this:

<html>
<head>
<script>
var xPar="";
if(window.location.href.match(/x=(\d+)/i))
  xPar=RegExp.$1
alert(xPar)
</script>
</head>
</html>

0
 
funkeCommented:

var urlString = "http://www.asfdjklasfd.com/card.html?x=123456";
var urlLength = url.length;

var lastSixDigits = urlString.substring( urlLength - 6, 6 );
0
 
knightEknightCommented:

function querystring(name)   // returns a named value from the querystring
{
     var tmp = unescape( location.search.substring(1) );
     var i   = tmp.toUpperCase().indexOf(name.toUpperCase()+"=");

     if ( i >= 0 )
     {
          tmp = tmp.substring( name.length+i+1 );
          i = tmp.indexOf("&");
          return( tmp = tmp.substring( 0, (i>=0) ? i : tmp.length ));
     }

     return("");
}


// and in this case, you can get the value of the x parameter like this:

alert( querystring("x") );
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
DwordCommented:
try this?

<script language="javascript">
var address = window.top.location.href
address = address.substring(address.length-6,address.length)
</script>
0
 
DwordCommented:
type wrongly use 6 instead of address.length

<script language="javascript">
var address = window.top.location.href
address = address.substring(address.length-6,6)
</script>
0
 
rJonesXAuthor Commented:
Thanks again to all of the posters who provided invaluable advice. I am awarding knightEknight because their comments went above and beyond the call of the question, providing me with a solution that would easily fit several future scenarios as well.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now