隔离URL参数

Isolate URL Parameters

本文关键字:参数 URL 隔离      更新时间:2023-09-26

我试图获得url参数(设备)并在正文中调用它。下面的代码工作得很好,除了它会显示为iPhone+4s*。有没有办法去掉+和*,只显示iPhone 4s?

url - http://mydomain.com/click.php?device=[[device_name]]

<script>
function getURLParameter(name) {
return decodeURI(
    (RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1] || ''
);
}
</script>

<body>
<script>document.write(getURLParameter('device'))</script>
</body>

您必须替换所有& + =,因为它们不会解码,因为它们是url编码中允许的字符。

uri = decodeURIComponent(uri);
uri = uri.replace(/'+/g, '-');