1

I have two URL's

url 1 = www.xyz.co.uk/asd.qmd
url 2 = www.xyz.co.uk/asd.qmd?getstep=4#

I want to show a div(left) when PAGE URL is www.xyz.co.uk/asd.qmd?getstep=4#

In the page form.php I wrote the following code:

<script>
    $(function(){
        var locate = window.location;

        if (locate=="http://localhost/school/form.php") {
            $('#left').hide();
        } else {
            $('#left').show();
        }
    });
</script>

<body  onload="function()">
    <div id="left">
        aasdsasdfdsgfg
    </div>
</body>

Why is this not working?

1
  • 1
    ok what about php condition ... this is stupid... Commented Sep 24, 2010 at 8:18

5 Answers 5

2

Just make php condition

<?php
if($_GET['getstep']){

}
?>
Sign up to request clarification or add additional context in comments.

Comments

1
$('#left').toggle(window.location.href !== "http://localhost/school/form.php");

Comments

0

You need to make a show/hide function the proper javascript way. What you are doing at first with the (I assume) jQuery is beyond me - just declare a simple function containing the code you already have to show/hide and attach it to the onload-event.

Comments

0

If you just want to hide the div when the query string is empty, you could use the search property of the window.location object:

$(function(){
      if (window.location.search === "") {
            $('#left').hide();
      } else {
            $('#left').show();
      }
 });

Anything more complicated (i.e. a different div for each page value) and I recommend you look at regex

Comments

0

You need to use the href property of the window.location object.

var locate = window.location.href,
  myElement = $('#left');
locate == "http://localhost/school/form.php" 
  ? myElement.show() 
  : myElement.hide();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.