Trying to write a javascript bookmarklet to jump from a front end link into a CMS edit page link.
So take a url like this
http://www.example.com/events/13097/article
and make a url like this
http://www.example.com/admin/edit.php?class=events&id=13097
I think I need to use regex to grab the class and id and then wrap it into a javascript function- but I’m a absolute beginner and wondering if someone can get me started?
You don’t need regex, Try this:
splits the class and the id from the URL and repeats them in the redirect.
the first line casts the
window.locationto a string you could also useString(window.location)to do this, but that’s more verbose.to get the domain too, you can use:
EDIT: Actually, you can get the
urlpartswithwindow.location.href.split('/')or to emulate the original codewindow.location.toString().split('/')other items of interest in thewindow.locationobject (examples from this post)