Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    window.location.search question

    I have a site that I am creating pages that adapt to different screen sizes. I am using a script for the regular pages that works like this:
    <script language="Javascript"><!--
    if (screen.width < 1000) {
    document.location = "showArticle2.asp";
    }
    //-->
    </script>

    Some of the pages have news stories that come from a database and typically the regular page would load something like this:
    http://www.mysite.com/news/showarticle?ArticleID=4162

    What I want to do since the main page uses the "http://www.mysite.com/news/showarticle.asp?ArticleID=4162" is to call the alternate page as shown above but it will do me no good unless I can ArticleID 4162.

    I tried this but it does not work:
    <script language="Javascript">
    if (screen.width < 400)
    window.location.replace("showArticle2.asp" + window.location.search);}
    //-->
    </script>

    Does anyone has any ideas how to make it work? Thanks in advance for any help.

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    You left out the ? between the page name and the search string.

    window.location.replace("showArticle2.asp?" + window.location.search

    The other thing you need to do is to change it to test the width inside the browser window instead of the screen width since someone with a screen width of 2000 may have their browser open using only say 500 of that width so as to see other things at the same time.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •