'How to mobilize all links with http://www.google.com/gwt/x?u=?

I've trying to make the links on some of my pages "mobilized" with this great service Google Mobilizer: http://www.google.com/gwt/x?u=

Is there a way to prefix all of the links within a div or element, so rather than the link be site.com/link it becomes http://www.google.com/gwt/x?u=site.com/link ?

I'm thinking that something like this might work:

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

I'm just not sure how to code it. If you know how it's done I would be very thankful!



Solution 1:[1]

I think this could be useful for you:

  1. Download the file Mobile_Detect.php at GitHub
  2. Put it on the root of your server
  3. Put this code at the beginning of every page you would redirect

    <?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 . '');}
    ?>
    

I tested it with this site and works fine

Solution 2:[2]

I wrote this Google Mobilizer bookmarklet as I had a itch to scratch.

You can adapt the code to suit your requirement.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 nixda
Solution 2 mvark