How to apply jQuery load () function on a page if I go to the page via spesific link

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

The first link is simple. it just goes to target.html.

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

just:

1-user clicks the second link to target.html

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

What can I 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 download them when I follow this link.

+5
source share
1 answer

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> 

Must work.

+5
source

Source: https://habr.com/ru/post/1242208/


All Articles