How to go to the next page using HTML and / or JS?

Is it possible to use HTML and / or Javascript to automatically determine what is the anchor of the next page and navigate to it?

+3
source share
4 answers

Assuming that you are referring to a known anchor / item; if you use jQuery, they have a selector for "Next Sibling"; find the documentation here:

http://api.jquery.com/next-siblings-selector/

I'm just ending; otherwise, I would create a complete selector for you, but if you don't have an answer later today, I'm going to compile it.

Edit

, , , ... ... ... ( , , JS).

Edit

100% ; , . , ; ( ).

var _anchorOffets = {};

$(document).ready(function () {
  $("A[id]:not(A[href])").each(function (index, value) {
    var $anchor = $(value);
    _anchorOffets[$anchor.attr("id")] = $anchor.offset().top;
  });
});

function getNextAnchorId() {
  var $window = $(window);
  var minOffset = $window.scrollTop() + $window.height();

  for (var anchor in _anchorOffets) {
    if (_anchorOffets[anchor] >= minOffset) {
      return anchor;
    }
  }

  return null;
}

, , , -

function getNextAnchorId() {
  var result = null;

  $("A[id]:not(A[href])").each(function (index, value) {
    var $anchor = $(value);
    var $window = $(window);
    var minOffset = $window.scrollTop() + $window.height();

    if($anchor.offset().top >= minOffset) {
      result = $anchor.attr("id");
      return false;
    }
  });

  return result;
}

. . - / div .., ( , ). , , , , . , , : D

+1

, - , , URL-. window.locaiton.hash. .

alert(window.location.hash);
+1

, , . , ...

function Next(){
    var lnkNext = document.getElementById("yourNextAnchorId");
    window.location.href = lnkNext.src;
}

, innerText

0

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


All Articles