Magento: Get url parameter with Javascript

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone

While I was working on latest version of extension for creating chooser button in admin forms I had to do small workaround in order to get url parameter with Javascript.

I developed simple RegEx that allowed me to extract url parameters that are enclosed with slashes. In the example below I am showing how to get parameter “entity_id”:

var url = 'http://example.com/catalog/product/view/entity_id/447/';
var regex = new RegExp('/\\entity_id\/([^\/]+)\/');
var entityId = regex.exec(url)[1]; // entityId = 447

Your thoughts?

Tweet about this on TwitterShare on LinkedInShare on Google+Share on FacebookEmail this to someone

Tsvetan Stoychev

Tsvetan aka. Cecko is the founder of Cecko's Lab. He is Magento addicted since Magento CE 1.2.1.2 and has worked on over 30 Magento projects. At the moment he is in charge to take care about the money flow of the company, to keep constant communication with the clients and to keep the people in the office busy.

More Posts

Follow Me:
TwitterLinkedIn