Home » Php » Get page URL from page A and show content from this page on page B

Get page URL from page A and show content from this page on page B

Posted by: admin October 26, 2017 Leave a comment

Questions:

I have 10 pages on my website. These pages contain different telephone numbers. I have an enquiry page where I want to display these telephone numbers. I want the telephone numbers to change depending on which page the user has visited previously. e.g. if a user visits a page showing 0800 numbers then clicks to go to my enquiry page, I want to show the content from the 0800 page on my enquiry page and so on. By default, the 0330 numbers are showing. I have created some code but the only problem is after the page has fully loaded, the numbers quickly change back to the default 0330 numbers. Below is my code…

<?php
if(isset($_SERVER['HTTP_REFERER'])) {

$PreviousUrl = $_SERVER['HTTP_REFERER'];

if ($PreviousUrl == "www.domain.com/0800-numbers/") { ?>

  <script type="text/javascript">
    jQuery(document).ready(function(){
      $ = jQuery;

        $("#range a#0330").removeClass('active');

          var thisrange = $(this).find('a#0800').attr('href');

          $(".filtering").load(''+thisrange+' .page-body');
              $("a#0800")[0].click(function(){
          }); 
     });

  </script>

<?php }

}
else { }

?>

So when the page loads, the 0800 numbers show for a few seconds then they change back to the default 0330 numbers. Am I doing something wrong in my code?
I do have another bit of code which triggers content load on this page. This is further up my page and looks like…

$("#range a").click(function(event){
   $('.filter-main .page-body').addClass('load-page');
   var thisrange = $(this).attr('href');

   $(".filtering").load(''+thisrange+' .page-body');

   $("#range a").removeClass('active');

   $(this).addClass('active');

   event.preventDefault();
   tabshow();
});

$('#range:nth-of-type(1) p a:first-child').trigger('click');

Is there a conflict?
Also, is there a better / cleaner solution?

Thanks

Answers: