jQuery smooth scrolling on a different webpage

I have managed to get the smooth scrolling working on a single page using the following code.

Note the HTML link is stored in a header.php and used across multiple pages below is a code snippet:

HTML Script:

<a class="item" href="index.php#contact">

<a name="contact"></a>

JS Script:

$('a[href="index.php#contact"]').click(function (e) { // user clicks on html link

    e.preventDefault();  // prevent the default behaviour that occurs in the browser

    var targetOffset = $('a[name="contact"]').offset().top; // define a variable to point at a particular section & offset from the top of browser

    $('body').animate( // create animation

        { scrollTop: targetOffset }, 1000); // scrollTop property = target variable



When I go to a different webpage and click the contact link it does not link back to the index.php#contact and scroll down to the contact anchor point.

Any assistance or advice is much appreciated I'm sure its a simple tweak in the code somewhere.


Check your href it's supposed to be: index.php/#contact

Need Your Help


sql postgresql count group-by

I have some data I am querying. The table is composed of two columns - a unique ID, and a value. I would like to count the number of times each unique value appears (which can easily be done with a...

Java: Dissecting a string

java string file

I have content inside of a file and I am trying to dissect certain portions of said content.