Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply jQuery's load() function on page if I go to page via specific link

I have two links at index.html to target.html.

first link is simple. it's just goes to target.html.

but I want to do something else with the second link.

simply:

1-user clicks the second link to target.html

2-not only target.html appears but also show-this-page-in-target.html-if-user-clicks-the-second-link.html appears in .page-class element with the help of jQuery load() function.

What I'm able to do so far?

I can load the page I want when I'm in target.html already with the codes below:

HTML

<a href="#" id="load" class="btn btn-primary">Load</a>

JavaScript

<script type="text/javascript">
$('#load').click(function(){
  $('.page-class').load('show-this-page-in-target.html-if-user-clicks-the-second-link.html .target-class')
}); 
</script>

But I don't know how to load them when I go that page via link.

like image 734
LetsSeo Avatar asked Feb 03 '16 13:02

LetsSeo


1 Answers

This is your second link to taget.html:

<a href="target.html#load" class="btn btn-primary">Load</a>

in target.html use this code:

<script>
if(window.location.hash === '#load') {
    $(function() {
        $('.page-class').load('show-this-page-in-target.html-if-user-clicks-the-second-link.html .target-class')
    });
}
</script>

Should work.

like image 122
IDontKnow Avatar answered Oct 31 '22 21:10

IDontKnow