从网址获取数据 [英] get data from url

查看:99
本文介绍了从网址获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从这里采取了一个准备好的脚本,如何读取GET数据从一个URL使用JavaScript?,并不能使它的工作,什么即时做错了?
这里是我的脚本:

  function getUrlParam(param)
{
param = param .replace(/([\ [\](){} *?+ ^ $。\\ |])/ g,\\ $ 1);
var regex = new RegExp([?&]+ param +=([^&#] *));
var url = decodeURIComponent(window.location.href);
var match = regex.exec(url);
返回匹配?匹配[1]:;
}
var param = getUrlParam(process_number);
alert(param);

以下是我的链接:

  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 

thx帮助!

对不起家伙,忘了mantion我的网页是在一个框架中工作,为什么它不能从我想要的url的数据:)

解决方案

由于您处于框架中,因此如果您需要从主窗口获取href,请执行以下操作:

  var href = window.top.location.href; 

然后处理它。


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)
{
  param = param.replace(/([\[\](){}*?+^$.\\|])/g, "\\$1");
  var regex = new RegExp("[?&]" + param + "=([^&#]*)");
  var url   = decodeURIComponent(window.location.href);
  var match = regex.exec(url);
  return match ? match[1] : "";
}
var param = getUrlParam("process_number");
alert(param);

and here is my link:

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

thx for the help!

Sorry guys, forgot to mantion that my page is working in a frame, that why it can't get the data from url i want :)

解决方案

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.

这篇关于从网址获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆