Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Detecting platform

Status
Not open for further replies.

drumin

Technical User
Mar 18, 2001
10
GB
I have this script on top of one of my pages to detect if the user is on a Mac...

<script LANGUAGE=&quot;JavaSCRIPT&quot;>
function platformversion()
{
var ua = window.navigator.userAgent
var platform = ua.indexOf (&quot;Mac&quot;)

if (platform = &quot;Mac&quot;)
response.redirect(&quot;/personal/online/demos/default_popup.htm&quot;)
else // If another platform, return 0
return 0

}
platformversion()
</script>

This does not appear to work. Can anyone tell me where I'm going wrong?

Many Thanks!

 
try this

mac=(navigator.platform==&quot;MacPPC&quot;)? true:false;

if the user platform is a Mac it will set the variable m,ac to true else it will be set to false.

you can then use

if(mac){
somefunction()
}

however your problem may be more to do with the use of response.redirect. This is a VB syntax NOT javscript. The equivalent javascript is

window.location.href = &quot;/personal/online/demos/default_popup.htm&quot;;




hope this helps

rob
 
Thanks for that. Still having problems. Here's what I have now...

<script LANGUAGE=&quot;JavaSCRIPT&quot;>
function platform()
{
var mac=(navigator.platform==&quot;MacPPC&quot;)?true:false;

if (mac){ = true then
window.location.href = &quot;/personal/online/demos/default_popup.htm&quot;;
else
return false
}

{
platform()
}
</script>

I'm sure it's something very obvious! Can you help again?

Thanks!
 
Hi,

rather that debug your code you can use the script below, adapted from apple developer resources. I've tested it across all mac platfroms, and IE/NE 4+. Hope it helps.

Cheers,
Graham.


(Can be used to handle all platforms see:
Check out the code samples.
---------------------------


var n = navigator;

var ua = ' ' + n.userAgent.toLowerCase();
var pl = n.platform.toLowerCase(); // not supported in NS3.0
var an = n.appName.toLowerCase();

// platform
var is_mac = ua.indexOf('mac') > 0;
var is_mac68k = (ua.indexOf('68k') > 0 || ua.indexOf('68000') > 0);
var is_macppc = (ua.indexOf('ppc') > 0 || ua.indexOf('powerpc') > 0);



if (is_mac==true || is_mac68k==true || is_macppc==true) {
// nasty, nasty mac, redirect to mac only URL
document.location=&quot;macpage.htm&quot;;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top