12 Replies Latest reply on Nov 9, 2008 8:58 PM by Newsgroup_User

    Simple PLATFORM detect script?

    Bentmen
      I'm hoping there's a simple solution for this -- I need it up and running before Monday.

      I've built two versions of a simple site: one stupid version for cel phones/blackberrys, etc., one sensible version for regular ol' Macs & PCs. The cel version is the default page. The one for computers is in a subfolder.

      Rather than get into an elaborate script that would attempt to account every kind of handheld that might hit the site, it seems like it should be easier to just simply detect for Mac & PC with javascript and route them accordingly to the subfolder. The handhelds should just ignore the javascript and stay where they are....... right?

      I'm not a javascript person, though -- so if anybody has a simple script that does this, I'd be most appreciative.

      Also, is my hypothesis about the handhelds simply ignoring javascript correct, or will they choke on it and not render the page?

      Many thanks!
        • 1. Re: Simple PLATFORM detect script?
          Level 7
          > The handhelds should just ignore the javascript and stay where
          > they are....... right?

          Wrong. Many (most? all?) visual phones do javascript.

          The right way to do this would be to build one page with a mobile media
          stylesheet - this stylesheet would dumb the page down (however, you'd be
          surprised how nice pages look on my iPhone) for cel phones, and let the page
          blossom on other media.

          --
          Murray --- ICQ 71997575
          Adobe Community Expert
          (If you *MUST* email me, don't LAUGH when you do so!)
          ==================
          http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
          http://www.dwfaq.com - DW FAQs, Tutorials & Resources
          ==================


          "Bentmen" <webforumsuser@macromedia.com> wrote in message
          news:gf4lp4$jjk$1@forums.macromedia.com...
          > I'm hoping there's a simple solution for this -- I need it up and running
          > before Monday.
          >
          > I've built two versions of a simple site: one stupid version for cel
          > phones/blackberrys, etc., one sensible version for regular ol' Macs & PCs.
          > The
          > cel version is the default page. The one for computers is in a subfolder.
          >
          > Rather than get into an elaborate script that would attempt to account
          > every
          > kind of handheld that might hit the site, it seems like it should be
          > easier to
          > just simply detect for Mac & PC with javascript and route them accordingly
          > to
          > the subfolder. The handhelds should just ignore the javascript and stay
          > where
          > they are....... right?
          >
          > I'm not a javascript person, though -- so if anybody has a simple script
          > that
          > does this, I'd be most appreciative.
          >
          > Also, is my hypothesis about the handhelds simply ignoring javascript
          > correct,
          > or will they choke on it and not render the page?
          >
          > Many thanks!
          >

          • 2. Re: Simple PLATFORM detect script?
            Bentmen Level 1
            >> Wrong. Many (most? all?) visual phones do javascript.

            Even so, they're not going to present themselves as a "Mac" or "PC," right? Frankly, I wouldn't even care if the iPhone gets routed to the nice site, it's looks fine on one of those. It's just that Blackberries and their ilk that need the bone-stupid version need to stay put.

            >> The right way to do this would be to build one page with a mobile media <<

            No time for that. The sites are already built and I have six other projects going this weekend. I just need a platform-redirect script.... anybody?
            • 3. Re: Simple PLATFORM detect script?
              Level 7
              If you don't have the time to do it right, where will you get the time to
              redo it?

              --
              Murray --- ICQ 71997575
              Adobe Community Expert
              (If you *MUST* email me, don't LAUGH when you do so!)
              ==================
              http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
              http://www.dwfaq.com - DW FAQs, Tutorials & Resources
              ==================


              "Bentmen" <webforumsuser@macromedia.com> wrote in message
              news:gf4p5l$ns0$1@forums.macromedia.com...
              >>> Wrong. Many (most? all?) visual phones do javascript.
              >
              > Even so, they're not going to present themselves as a "Mac" or "PC,"
              > right?
              > Frankly, I wouldn't even care if the iPhone gets routed to the nice site,
              > it's
              > looks fine on one of those. It's just that Blackberries and their ilk
              > that
              > need the bone-stupid version need to stay put.
              >
              > >> The right way to do this would be to build one page with a mobile media
              > >> <<
              >
              > No time for that. The sites are already built and I have six other
              > projects
              > going this weekend. I just need a platform-redirect script.... anybody?
              >

              • 4. Re: Simple PLATFORM detect script?
                Bentmen Level 1
                Like I said, I'm not a javascript person. Is it too much to ask for a simple bit of syntactical guidance?

                In pseudo code, here's the function I need:

                Get the platform info and stick it in a variable.
                If the variable contains "Mac" or "Win", go to /site2/index.html

                The End.

                Here's what I've been able to piece together so far from looking at other scripts.

                <SCRIPT LANGUAGE="JavaScript">

                function detectBrowser() {
                bUserAgent = navigator.userAgent;

                // this is where I need to know how to do a "contains" to check for Mac or Win
                // and route it to site 2

                }

                </SCRIPT>
                • 5. Re: Simple PLATFORM detect script?
                  Level 7
                  > Like I said, I'm not a javascript person. Is it too much to ask for a simple
                  > bit of syntactical guidance?
                  >
                  > In pseudo code, here's the function I need:
                  >
                  > Get the platform info and stick it in a variable.
                  > If the variable contains "Mac" or "Win", go to /site2/index.html
                  >
                  > The End.
                  >
                  > Here's what I've been able to piece together so far from looking at other
                  > scripts.
                  >
                  > <SCRIPT LANGUAGE="JavaScript">
                  >
                  > function detectBrowser() {
                  > bUserAgent = navigator.userAgent;
                  >
                  > // this is where I need to know how to do a "contains" to check for Mac or Win
                  > // and route it to site 2
                  >
                  > }
                  >
                  > </SCRIPT>

                  And a simple search for "javascript OS detection" (you could even add
                  tutorial to that search) didn't turn up a single usable result? Odd...

                  >
                  >

                  --
                  Kim
                  ---------------------------
                  http://www.geekministry.com

                  • 6. Re: Simple PLATFORM detect script?
                    Level 7
                    "Bentmen" <webforumsuser@macromedia.com> wrote in message
                    news:gf4thg$t16$1@forums.macromedia.com...
                    > Like I said, I'm not a javascript person. Is it too much to ask for a
                    > simple
                    > bit of syntactical guidance?
                    >
                    > In pseudo code, here's the function I need:
                    >
                    > Get the platform info and stick it in a variable.
                    > If the variable contains "Mac" or "Win", go to /site2/index.html
                    >
                    > The End.
                    >
                    > Here's what I've been able to piece together so far from looking at other
                    > scripts.
                    >
                    > <SCRIPT LANGUAGE="JavaScript">
                    >
                    > function detectBrowser() {
                    > bUserAgent = navigator.userAgent;
                    >
                    > // this is where I need to know how to do a "contains" to check for Mac or
                    > Win
                    > // and route it to site 2
                    >
                    > }
                    >
                    > </SCRIPT>


                    Rather than checking for UAs or OSes, why not checking the width of body?
                    You could set a session variable depending on the value returned by
                    offsetWidth.



                    --
                    Thierry
                    http://www.TJKDesign.com/go/?0 | Articles and Tutorials


                    http://divahtml.com/products/scripts_dreamweaver_extensions.php | Extensions
                    that keep your markup clean
                    http://www.fourlevel.com/ | CSS Menus, Gallery, Tab Panels, etc
                    --

                    • 7. Re: Simple PLATFORM detect script?
                      Bentmen Level 1
                      >>Rather than checking for UAs or OSes, why not checking the width of body? You could set a session variable depending on the value returned by offsetWidth.
                      <<

                      It's a thought, but it sounds more complex and less infallible to me than simply checking for the userAgent.

                      Do you know of any Blackberries that will present themseves as a "Mac" or "Windows" device?

                      What do you think of this?

                      //

                      <SCRIPT LANGUAGE="JavaScript">
                      <!--

                      function detectBrowser() {

                      var OSName="";
                      if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
                      if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

                      if (OSName="Windows" || OSName="MacOS") {
                      this.location.href = " http://www.mysite.com/site2/index.html"
                      }

                      //-->
                      </SCRIPT>

                      See any problem with that?
                      • 8. Re: Simple PLATFORM detect script?
                        Level 7
                        "Bentmen" <webforumsuser@macromedia.com> wrote in message
                        news:gf73d8$qgi$1@forums.macromedia.com...
                        >>>Rather than checking for UAs or OSes, why not checking the width of body?
                        >>>You
                        > could set a session variable depending on the value returned by
                        > offsetWidth.
                        > <<
                        >
                        > It's a thought, but it sounds more complex and less infallible to me than
                        > simply checking for the userAgent.

                        More complex? We're talking about one line of code here ;-)
                        Besides, checking for the user agent is often refered to "sniffing" and it
                        is considered bad practice as it is not reliable and it goes against the
                        idea that one should check for capabilities (support for a property for
                        example) and nothing else.



                        --
                        Thierry
                        http://www.TJKDesign.com/go/?0 | Articles and Tutorials


                        http://divahtml.com/products/scripts_dreamweaver_extensions.php | Extensions
                        that keep your markup clean
                        http://www.fourlevel.com/ | CSS Menus, Gallery, Tab Panels, etc
                        --

                        • 9. Simple PLATFORM detect script?
                          Bentmen Level 1
                          Oops -- meant to say:

                          <SCRIPT LANGUAGE="JavaScript">
                          <!--

                          function detectBrowser() {


                          var OSName="Unknown OS";
                          if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
                          if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";

                          if (OSName=="Windows" || OSName=="MacOS") {
                          this.location.href = " http://www.mysite.com/site/index.html"
                          }

                          }

                          //-->
                          </SCRIPT>

                          • 10. Re: Simple PLATFORM detect script?
                            Bentmen Level 1
                            >> width of body
                            >> More complex? We're talking about one line of code here ;-)

                            You can distinguish between all the different possible monitor vs. handheld resolutions with one line of code?

                            Example?

                            ..Or would you say "over 640 wide" or something like that...?
                            • 11. Re: Simple PLATFORM detect script?
                              Bentmen Level 1
                              Some answers:

                              http://www.hand-interactive.com/resources/detect-mobile-javascript.htm

                              Includes a downloadable javascrript file to include. Then just make a call to DetectMobileLonger() which returns a boolean. If it's false, redirect.

                              Works fine now.
                              • 12. Re: Simple PLATFORM detect script?
                                Level 7
                                Bentmen wrote:
                                > Some answers:
                                >
                                > http://www.hand-interactive.com/resources/detect-mobile-javascript.htm
                                >
                                > Includes a downloadable javascrript file to include. Then just make a call to
                                > DetectMobileLonger() which returns a boolean. If it's false, redirect.
                                >
                                > Works fine now.
                                >
                                why not:
                                <script>if(window.screen.width>600)location="index.html"</script>

                                ?
                                Mick