Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Returning to the Top of the current page.


T. Thomas

Recommended Posts

Posted

I'm currently trying to fix a bug in my footer that I didn't know was there or recently popped up. In my footer I have a link that says "return to top" now on all of my other site software(Wordpress, phpBB) it gets the current page and returns the browser to the top of that page, but on OScommerce it just returns to the front page no matter what page I'm on in my webstore. Obviously this isn't what I want to happen but I can't seem to be able to get this bug worked out. If you could take a look at my code and point out what I'm doing wrong or what I could be doing better I would really be grateful. Below is the code from my english.php file

 

define('FOOTER_TEXT_BODY'... <a title="Go to top" href="#">Go to top ↑</a></div>');

 

I've tried looking up different ways to do this but they either fail on the “right click → new tab” or they just don't work. Is there a different/better way to do this using html or maybe even a built in osCommerce way that I’m over looking?

Posted

Replace:

 

<a title="Go to top" href="#">Go to top ↑</a>

 

TO:

<a title="Go to top" id="TopOfPage">Go to top ↑</a>

 

Assuming you use version 2.3.x:

Open: includes/template_top.php

 

Find:

 

<script type="text/javascript" src="ext/jquery/ui/jquery-ui-1.8.22.min.js"></script>

 

Below add:

 

<script>
$(document).on('click','#TopOfPage', function() {
$("html, body").animate({ scrollTop: 0 }, "slow");
return false;
});
</script>

Posted

If you want to keep the href way:

 

change:

<a title="Go to top" href="#">Go to top ↑</a>

 

To:

<a title="Go to top" href="#TopOfPage">Go to top ↑</a>

 

And for the template_top.php:

 

$(document).on('click','a[href="#TopOfPage"]', function(e) {
e.preventDefault();
//alert('clicked');
$('html, body').animate({scrollTop:0}, 'slow');
return false;
});

 

The event now prevents the default action , what is in this case that the browser wants to goto #TopOfPage ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...