[quoted text, click to view] domtam@hotmail.com wrote:
> My goal is to add some script to my home page (which is
> NOT asp / aspx page, and it is not hosted in IIS) so that
> any request from mobile browser will be redirect to another
> page (a wap page which uses asp.net mobile control page).
> How can I do that?
Redirecting with client-side scripts is generally considered the worst
method available. It certainly is not reliable.
[quoted text, click to view] > Originally, I planned to use Javascript to do it.
>
> <script language="javascript">
> var agt = navigator.userAgent.toLowerCase();
The userAgent string is a reflection of the browser's User-Agent header,
and HTTP 1.1 specifies the User-Agent header in a way that precludes it
being regarded as a source of information. (That is, this strategy is
predicated upon a false assumption.)
[quoted text, click to view] > var is_mobile = ( (agt.indexOf("blacknerry") != -1)
>|| (agt.indexOf("nokia") != -1)
>|| (agt.indexOf("WebtV") != -1)
This condition can never be true as your string contains only lower case
letters as a result of the use of - toLowerCase -.
[quoted text, click to view] >|| (agt.indexOf("windows ce") != -1)
>|| (agt.indexOf("microsoft pocket internet explorer") != -1)
>|| (agt.indexOf("up") != -1)
You are going to regard any userAgent string that contains the character
sequence 'up' as a mobile?
[quoted text, click to view] > // more different mobile browser user agent here.
>
> );
> var mobile_url = "http://wap.mydomain.com";
> if (is_mobile)
> window.location = mobile_url;
>
> </script>
>
> It worked with Pocket PC IE, but it didn't work with
> BlackBerry browser (emulator).
>
> I suspect that it's because the blackberry browser doesn't
> understand javascript. Is that true?
I don't know. It may be incapable of interpreting javascript, or its
interpreter may be disabled by default (either are common with embedded
browsers).
[quoted text, click to view] > If it is the case, it probably won't work
> for other mobile browser too.
Yes, it won't work with many embedded browsers, including the ones that
spoof IE in their UA strings.
[quoted text, click to view] > Is there a better solution to this problem?
Content negotiation on the server, as per HTTP 1.1 (RFC 2616) (so not a
javascript question). You serve WAP pages to browsers that send Accept
headers expressing a preference for them. Mobile browsers that support
WAP can be expected to do that.
Richard.