我想从浏览器的网址中获取7位数字,如下所示:
www.example /?id = 1122331
并将7位数添加到另一个链接。
这是链接wwww.referece.com/ref
的基础并更改为
wwww.referece.com/ref1122331
。
答案 0 :(得分:0)
好吧,我建议你使用PHP。 要在PHP中获取ID值,请执行以下操作
<?php
$id = $_GET['id']; //here we grab the 7 digits and place them into $id var
// Now lets build the new link
$link = "www.referece.com/ref".$id; //values are concatenated and we get www.referece.com/ref1122331
?>
答案 1 :(得分:0)
选项1:您可以使用javascript在客户端执行此操作,例如how-to-get-the-value-from-the-url-parameter
选项2:你可以做服务器端(Java / Php / Python等等 - 依赖你的服务器端语言)
答案 2 :(得分:0)
1)您可以使用 PHP 从服务器端执行此操作,如下所示:
// Get the url of the browser
var link = document.location.href;
// Get the 7-digit number
var number = (link.indexOf("=")) ? link.substr(link.indexOf("=")+1, link.length) : null;
// Add the 7-digit number to a new link and return it
var newLink = "wwww.referece.com/?ref=" + number;
2)或者,要从客户端执行此操作,您可以使用 JavaScript ,如下所示:
// Create button
var button = document.createElement("a");
button.setAttribute("href", newLink);
document.body.appendChild(button);
[编辑]:↓
public boolean isDecimal(String str) {
try {
Double.parseDouble(str);
}
catch(NumberFormatException ex) {
return false;
}
return true;
}
答案 3 :(得分:0)
最典型的解决方案涉及服务器端处理,PHP,ASP,JSP
对于JSP
<a href="wwww.referece.com/ref<%= request.getParameter("id") %>"
会这样做。
客户端也可以使用javascript。
以下是如何覆盖链接的目标:
JavaScript function in href vs. onclick
以下是获取参数的方法:
答案 4 :(得分:0)
document.location.href
这抓住了网页的网址。让我们说原始页面ulr是这个“https://stackoverflow.com/questions/
用户在网址上手动执行此操作。 ?mid=123456
新网址“https://stackoverflow.com/questions/?mid=123456
现在的目标是提取此号码123456并附加到新网址。 这是一个用户传递参数到操作按钮到URL。每个用户参数都是唯一的,长度始终为7位。