So I have a URL and I know how to get $_GET from URL however my URL is http://www.example.com/#!/edit/2695
.
Is there away to grab the url and spit the parts after #!/
? I want edit and the ID.
You can use this code
var url = "http://www.mysite.com/#!/edit/2695";
var pieces = url.split("/#!/");
pieces = pieces[1].split("/");
// pieces[0] == "edit"
// pieces[1] == "2695"
If you just wanted the number after the edit, you could also use a regex
var url = "http://www.mysite.com/#!/edit/2695";
var match = url.match(/#!\/edit\/(\d+)/);
if (match) {
// match[1] == "2695"
}
You can see both of them work here: http://jsfiddle.net/jfriend00/4BTyH/
var edit = window.location.hash.split('/')[1],
ID = window.location.hash.split('/')[2];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With