Skip to content Skip to sidebar Skip to footer

Get Data From Url

i took a ready script from here, How to read GET data from a URL using JavaScript? and can't make it work, what im doing wrong? here is my script: function getUrlParam(param) { p

Solution 1:

Since you're in a frame, if you need to get the href from the main window, do this:

var href = window.top.location.href;

Then process it.

Solution 2:

That code has to run from the page whose URL you're mining for parameter values. In other words, it operates only on the current URL of the page it's on. It works fine.

If you want a function that gives you parameter values given an arbitrary URL, you'd just need to add an additional parameter:

functiongetUrlParam(param, url) {
  param = param.replace(/([\[\](){}*?+^$.\\|])/g, "\\$1");
  var regex = newRegExp("[?&]" + param + "=([^&#]*)");
  url   = url || decodeURIComponent(window.location.href);
  var match = regex.exec(url);
  return match ? match[1] : "";
}

alert(getUrlParam("process_number", "http://erp.micae.com/index.cfm?fuseaction=objects.popup_print_files&process_number=SER-498&action_type=141&action_id=289&action_row_id=32&print_type=192"));

Post a Comment for "Get Data From Url"