dcsimg
www.webdeveloper.com
Results 1 to 3 of 3

Thread: My code just keeps refreshing the page :(

  1. #1
    Join Date
    Mar 2005
    Location
    Western USA
    Posts
    206

    My code just keeps refreshing the page :(

    I have a page that loads different information based on the id found in the address bar. Using that, I wanted to add an image based on the id. Here it is below
    <HEAD>
    <script type="text/javascript">
    if (window.location.href='design.php?id=HelmetStickers'){
    document.write('<img src="image/greybox.png" class="greybox1">');
    }
    </script>
    </HEAD>

    The local page I'm viewing is 8089/local-release/design.php?id=HelmetStickers

    When I open the page with this code, it just keeps refreshing every half second. What am I missing? I just want to add an image based on the ID.
    Thanks!

  2. #2
    Join Date
    Dec 2012
    Posts
    259
    You need to use 2 equal signs when comparing values

    Code:
    <HEAD>
    <script type="text/javascript">
    if (window.location.href == 'design.php?id=HelmetStickers'){
    document.write('<img src="image/greybox.png" class="greybox1">');
    } 
    </script> 
    </HEAD>

  3. #3
    Join Date
    Mar 2005
    Location
    Western USA
    Posts
    206
    Quote Originally Posted by iBeZi View Post
    You need to use 2 equal signs when comparing values

    Code:
    <HEAD>
    <script type="text/javascript">
    if (window.location.href == 'design.php?id=HelmetStickers'){
    document.write('<img src="image/greybox.png" class="greybox1">');
    } 
    </script> 
    </HEAD>
    That worked! Thanks

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles