Restricted Pages

Translate

StatCounter

Page authors

  • Robert Wilcox
    February 8, 2013

Recent site activity

Site owners

  • Stephen Hind
  • Bob Oms
  • robertwilcox
  • Robert Wilcox

Mobile Redirect

You can build a mobile landing page by using one of several available templates. Instructions are here.

There have been requests in the help forum for a method of automatically redirecting a desktop site to the mobile site for visitors using mobile devices. Someone posted some JavaScript that would accomplish this task. Since JavaScript is not allowed in Google Sites a gadget must be used. Creating Google Gadgets is explained in this article.

4April2012: The Gadget Editor is broken. I don't know why it has not been fixed.
7April2012: Mori's Gadget Editor appears to be working

The code I used in my gadget is:

<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs 
title="Mobile Redirect"
width="10"
height="10">
</ModulePrefs>
<UserPref name="url" display_name="URL to redirect to" required="true" default_value="http://" />
<Content type="html"><![CDATA[
<script type="text/javascript">
var prefs = new gadgets.Prefs();
var Xurl = prefs.getString("url");
var mobile = (/iphone|ipad|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
parent.location = Xurl;
}
</script>
]]></Content>
</Module>

Thanks to the help forum poster PBS web for the original idea and to forum poster and gadget guru Mori79 for his help.

To try it edit your page, click Insert, select More gadgets, then Add gadget by URL. Insert this address:

http://hosting.gmodules.com/ig/gadgets/file/117770694006921265528/redirect_mobile.xml

Enter the URL that you want to redirect to in the URL to redirect to box. Be sure to include the 'http://'. 

Remove the check from Include a border around gadget and Display title on gadget.

There is another redirect gadget available. I don't know if is different than mine but it seems to work well. To use it search for 'DudaMobile Mobile Redirect' in the public section of the gadgets.

You can test the operation of your gadget in Firefox if you add the User Agent Switcher extension.

If you view this site's home page with a mobile device please fill out this form.

Mobile Gadget Survey


Results

Mobile Gadget Survey


Comments