1

Here http://files.giro54.net/fede/table-anchor/link-src.html I have a page with two links, the first one goes to a page with five tables generated by datatables plugin, and the second link to a plain simple static html also with five tables. Both links are pointing to the 5th table in the destination pages. The second link works as expected: it scrolls to the 5th table on the static html. But The first link doesn't scroll at all.

I spent a couple of hours trying to solve this. :( Thank you.

Fedegiro
  • 33
  • 2
  • 9

1 Answers1

0

Why is this happening?

The scrolling is automatic for the static html page by default (this could potentially be a browser issue). There are several fixes to this issue, I will let you decide which is the most appropriate to solve the problem:

How can I solve this?

Just as this problem for the JQuery has not solved itself by default, you can do it dynamically (like everything else we can do with JS/JQ):

1. Include the following in your $document.ready:

$window.scrollTo(0,document.body.scrollHeight);

2. Grab the element you want, and put it into the viewport:

$document.getElementById( 'bottom' ).scrollIntoView();

As said, there are several ways of solving this, and the problem lies in the JQuery vs. static and how it is being served to the browser of choice, these fine tuning parameters are set to default in some browsers and not in others.

PS: Word to the wise, don't post links to your site, just images and code snippets. This may hinder your answers from others in the future.

Community
  • 1
  • 1
bmc
  • 671
  • 11
  • 15
  • thanks for the answer @bmc. I tried the jquery option but now i'm getting the alert "$window is not defined" in the console. – Fedegiro Jan 20 '17 at 03:17
  • I am not sure how you are trying to use $window, but the syntax looks alot [like this](http://stackoverflow.com/questions/4655273/jquery-window-scrolltop-but-no-window-scrollbottom), similar to the `$(document).ready` synax. – bmc Jan 20 '17 at 03:24
  • sorry, i don't have too much jQuery skills. `$(document).ready(function() { $window.scrollTo(0,document.body.scrollHeight); });` – Fedegiro Jan 20 '17 at 08:20
  • i still have this issue. $window.scrollTo(0,document.body.scrollHeight); throws "Uncaught ReferenceError: $window is not defined" inside $document.ready. I updated the link test html. – Fedegiro Jan 24 '17 at 10:22
  • Potentially you could try to Jquery equivalent: $(window).scrollTo( ... ) – bmc Jan 24 '17 at 15:36
  • i'm trying with your jquery code, now it says "$(...).scrollTo is not a function". – Fedegiro Jan 25 '17 at 05:04
  • No ko, the scrollTo what meant to get you started in the right direction with a google search by the ...notation. Try looking up the function and seeing what arguments it needs. – bmc Jan 25 '17 at 13:22