Javascript to Get Slug of a Current URL

Javascript to Get Slug

javascript:var one = "http://" + document.domain + "/"; var two = self.location.href; var three = two.replace(one,""); var four = three.replace("/",""); alert(four);

Copy the script to your Browser’s Address bar and checkout the magic. Modify it as per your needs.

Here’s a code I used for one of my CMS which requires slug as an ID to Edit the current page.

javascript:var one = "http://" + document.domain + "/"; var two = self.location.href; var three = two.replace(one,""); var four = three.replace("/",""); window.location.href="http://" + document.domain + "/admin/edit.php?id=" + four;

Leave a comment

Your email address will not be published. Required fields are marked *