Jump to content


Photo

parsing url in js


  • Please log in to reply
1 reply to this topic

#1 DrTrans

DrTrans
  • Members
  • PipPipPip
  • Advanced Member
  • 179 posts

Posted 16 July 2017 - 07:53 PM

Looking to do a inline java parse 

 

onblur="return parseUrl()"; 

 

function parseUrl()  {

 

  // val = http://test.com/test/john/1/2/3;

var val = $(this).val();

 

 i need it to return the "john/1/2/3" part 

 

 

 

any assistance would be appreciated , thanks in advance.


Edited by DrTrans, 16 July 2017 - 07:54 PM.

Designing the web, www.OneDelve.com


#2 denno020

denno020
  • Members
  • PipPipPip
  • Advanced Member
  • 739 posts
  • LocationAustralia

Posted 16 July 2017 - 10:39 PM

You can use string split method on val:

var val = "http://test.com/test/john/1/2/3";
 
var parts = val.split('/');

Parts now has each part of the URL in an array, with the last 4 entries being 'john', '1', '2' and '3'.

 

You could also do a string replace, if 'http://test.com/test/" is always going to be exactly that

var val = "http://test.com/test/john/1/2/3";
var params = val.replace('http://test.com/test/', '');

They're 2 very basic ways to manipulate the URL string






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users