【问题标题】:HTML string concatenation from the browser link来自浏览器链接的 HTML 字符串连接
【发布时间】:2016-07-02 23:53:18
【问题描述】:

我想从浏览器的url中获取7位数字,如下所示:

www.example/?id=1122331 并将 7 位数字添加到另一个链接。

这是链接wwww.referece.com/ref 的基础并更改为 wwww.referece.com/ref1122331.

【问题讨论】:

  • 对此,你应该看看javascript,我猜。
  • 不清楚你在问什么。您只想重定向用户吗?即从www.example.com/?id=1122332发送流量到www.example2.com/ref1122332?
  • 这是许多不同会员使用的漏斗。每个会员都有自己的 ID。在重复漏斗的状态下,我虽然我们可以做一些事情 www.example.com/?id=1122332 ,其中 7 位数字是会员的 ID 号。当他们与他们的潜在客户分享这个漏斗时,id 将连接到 sing up 链接。这是一个示例链接 www.example2.com/ref1122332

标签: html wordpress string-concatenation


【解决方案1】:

为此,我建议您使用 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
?>

【讨论】:

    【解决方案2】:

    选项 1:您可以在客户端使用 javascript,例如 how-to-get-the-value-from-the-url-parameter

    选项 2:您可以在服务器端进行(Java/Php/Python 等 - 取决于您的服务器端语言)

    【讨论】:

      【解决方案3】:

      最典型的解决方案涉及服务器端处理,PHP、ASP、JSP

      对于 JSP

      <a href="wwww.referece.com/ref<%= request.getParameter("id") %>" 
      

      会做的。

      客户端也可以使用 javascript。

      以下是如何覆盖链接的目标:

      JavaScript function in href vs. onclick

      这里是如何获取参数:

      How to retrieve GET parameters from javascript?

      【讨论】:

        【解决方案4】:

        1) 您可以使用 PHP 从服务器端执行此操作,如下所示:

        <?php
            // Get the url of the browser
            $url = isset($_SERVER["REQUEST_URI"]) ?  $_SERVER["REQUEST_URI"] : "";
        
            // Get the 7-digit number
            $number = strpos($url, "=")>0 ? substr($url, strpos($url, "=")+1, strlen($url)) : "";
        
            // Add the 7-digit number to a new link and return it
            return $link = "wwww.referece.com/?ref=" . $number;
        ?>
        

        2) 或者,要从客户端执行此操作,您可以使用 JavaScript,如下所示:

        // 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;
        

        [编辑]:↓

        // Create button
        var button = document.createElement("a");
        button.setAttribute("href", newLink);
        document.body.appendChild(button);
        

        【讨论】:

        • 也许我没有解释清楚。这就是我想要实现的目标,我正在使用 work Press。这是网站? onlinetradingfloors/id=0123456 "0123456" 将由每个用户更改。用户可以插入他们的唯一号码,但号码始终是 7 位数字。我想抓住 7 位数字并形成一个新的链接,用于号召性用语按钮。 likesxl.com/ref0123456 怎么能在 word press 限制的情况下做到这一点?我很感谢你的帮助。
        • 这正是我的代码所做的。只需将 newLink 放入href。看看我编辑。
        【解决方案5】:
        document.location.href
        

        这会抓取页面网址。假设原始页面 ulr 是这个`https://stackoverflow.com/questions/

        用户在 url 上手动输入。 ?mid=123456 新网址`https://stackoverflow.com/questions/?mid=123456

        现在的目标是提取这个数字 123456 并附加到新的 URL。 这是用户通过 URL 将参数传递给操作按钮。每个用户参数都是唯一的,长度总是7位。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-12-08
          • 2015-10-23
          • 2016-04-03
          • 2017-06-15
          • 2021-02-24
          • 2015-05-28
          • 1970-01-01
          • 2023-02-10
          相关资源
          最近更新 更多