0

My url (localhost) :

http://localhost/nana-appication/public/

or

http://localhost/nana-appication/public/home

My url (server) :

http://dsp.nana.com/public/

or

 http://dsp.nana.com/public/home

I want to eliminate :

Localhost : http://localhost/nana-appication/

Server : http://dsp.nana.com/

So when I run console.log or alerts in javascript, a result like this :

localhost or server :

public/

or

public/home

Thank you

moses toh
  • 12,344
  • 71
  • 243
  • 443

2 Answers2

1

Try this:

var a = 'http://localhost/nana-appication/public/home';
var b = a.replace(a.split(/public.*/)[0],'');
console.log(b); // 'public/home'

(First you explode the string by '/public.*', then replace first part with empty string).

n-dru
  • 9,285
  • 2
  • 29
  • 42
0

I think this is a repeat of https://stackoverflow.com/a/736970/5741308 (which is brilliant).

Read down as a later answer addressed relative paths and IE strangeness.

Community
  • 1
  • 1
S.Pote
  • 71
  • 1
  • 5