如何通过http://www.google.com/gwt/x?u=动员所有链接?

时间:2013-04-20 02:28:52

标签: javascript redirect mobile prefix

我试图通过这款出色的服务Google Mobilizer“动员”我的部分网页上的链接:http://www.google.com/gwt/x?u=

有没有办法为div或元素中的所有链接添加前缀,所以而不是链接是site.com/link它会变成http://www.google.com/gwt/x?u=site.com/link

我认为这样的事情可能有用:

if (window.location == $LINK)
    window.location = "http://www.google.com/gwt/x?u=" + $LINK;

我只是不确定如何编码。如果你知道它是如何完成的,我将非常感激!

2 个答案:

答案 0 :(得分:0)

我认为这对你有用:

  1. 在GitHub下载文件Mobile_Detect.php
  2. 将其放在服务器的根目录
  3. 将此代码放在您要重定向的每个页面的开头

    <?php
    include('Mobile_Detect.php');
    $detect = new Mobile_Detect();
    if ($detect->isMobile()) {header('Location: http://www.google.com/gwt/x?u=http://' . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"],PHP_URL_PATH . '');}
    ?>
    
  4. 我使用this site进行了测试,效果很好

答案 1 :(得分:0)

我写了Google Mobilizer bookmarklet as I had a itch to scratch

您可以根据自己的要求调整代码。