简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM