0

I'm developing this website: http://parkoura.tk/a/sandbox/

I am using an ajax navigation. I have a function called ajax() which is supposed to execute at onload. When it does, I would like it to check first if a hashtag is there. If there is no hashtag, the function then should just break and not do anything. If a hashtag is declared, it sends ajax to another php and replaces content inside a div.

It works perfectly besides the onload hash tag checking part. When the site loads up, you can see for a moment that a slider is rendered. Despite the fact that no hashtag is declared, it then still goes on to replace the content.

I have alerts to show how the logic should be working. My logic for the actual checking is this:

    <script>
    if (typeof location.hash != 'undefined' || location.hash != '' || location.hash != '#' || location.hash != '#carousel')
    { no hash,things stay the same the function is not executed. 

full js code: https://pastee.org/v8cxp

stackOverFlew
  • 1,449
  • 1
  • 30
  • 56

1 Answers1

1

Try this :

if(window.location.hash) {
    // Process your ajax call
} else {
    // "no hash,things stay the same the function is not executed. "
}

Possible duplicate of : How can you check for a #hash in a URL using JavaScript?

Community
  • 1
  • 1
jbrtrnd
  • 3,675
  • 5
  • 23
  • 41
  • @user1392515 In relation to your code snippet, you can add in the `if` syntax : `&& window.location.hash != '#carousel'` – jbrtrnd Jun 19 '12 at 15:38