0

I have my page so far: einserpasch.com

The crucial markup is this:

<ul>
  <li><a href="#content_01" id="content_01"> !?! </a></li>
</ul>

And the div-container at the end of the document:

<div id="haupt_iframe">
</div>

On clicking on the drop down menu items the jQuery function loads content from a HTML file into the div container (I omitted the fading in the code below) while the URL in my browser gains the #-tag ending (like einserpasch.com/#content_01):

$(document).ready(function(){
    $("li a").click(function(){ 
    var knopf = $(this).attr('id');
    $("#haupt_iframe").load("bilder/"+knopf+".html");               
});

So far no problem.
but now I want a direct link to the different galleries. To make the images show in the div container only by typing in the correct URL including the #-sign.
the idea was that having an hash sign in the URL would make me get an id selector when i read it with window.location.hash. I tried to manage it like this:

$(document).ready(function(){    
  if(window.location.hash){
  $(window.location.hash).trigger(function(){
    var knopf = $(this).attr('id');
    $("#haupt_iframe").load("bilder/"+knopf+".html");
  });
  };
});

But so far, only the click on the a attribute fires the function but not typing in the URL with the specific #-tag at the end. like einserpasch.com/#painting.

So what am I missing to make me have a direct link?

Thanks in advance!
clemens :)

ps.: yes, i posted this in code review because i wanted you to review my code. but as a part of my code doesn't work the post was closed. i'm still learning the rules of this community...

1 Answer 1

1

If my understanding for your question is correct, you can change your code

$(document).ready(function(){    
  if(window.location.hash){
    var knopf = window.location.hash.substr(1);
    $("#haupt_iframe").load("bilder/" + knopf + ".html");
  };
});

Hope this help.

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

1 Comment

i would love to do so but i don't have enough reputation to vote for your answer ;)

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.