I have been trying fetching the query string from url using javascript.
I am using following code
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
$(document).ready(function() {
prodId = getParameterByName('id');
prodName = getParameterByName('name');
});
It works well for URL like http://my_ip/main.html?id=123&name=test
But when URL is like http://192.168.0.216:1009/main.html#!/video.html?id=123&name=test it fails, giving empty string for prodID and prodName
http://192.168.0.216:1009/main.html?id=123&name=test#!/video.html#if it's intended to be part of the pathname.