Running jQuery after loading a page after clicking on a specific link

I have a link in my application, which when clicked on it leads to another page. I want to execute jQuery on this new page after loading, but only if this particular link is clicked to go to the page.

I have this jQuery:

    $('#new_to_topics').click(function(){
        $(document).ready(function() {
            $('#topic_guidelines').slideDown('normal');
            $('#topic_guidelines').addClass('on');
        });
    });

where #new_to_topicsis the identifier of the link that leads to the new page, and

$('#topic_guidelines').slideDown('normal');
$('#topic_guidelines').addClass('on');

is the jQuery code that I want to execute on this new page. However, this does not work. How should I do it?

+5
source share
3 answers

You can pass the location hash to a new page, and then conditionally run some javascript based on this hash.

mynewpage.html#fromXlink ( )

javascript mynewpage.html :

$(document).ready(function() {
  if (location.hash == '#fromXlink') {
    $('#topic_guidelines').slideDown('normal');
    $('#topic_guidelines').addClass('on');
  }
});
+5

, somepage.aspx? fromthislink = true jquery.

,

, jquery.

+1
0

All Articles