我试图获取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>
答案 0 :(得分:0)
您必须只替换所有& + =
,因为它们不会解码,因为它们是url-encoding中允许的字符。
uri = decodeURIComponent(uri);
uri = uri.replace(/\+/g, '-');