Go next/previous page

Description

Finds and follows the next/previous link on the page. This is very useful for navigating search results.

JavaScript

Next Page

(function() {
	var el = document.querySelector("[rel='next']");
	if (el) { // Wow a developer that knows what he's doing!
		location = el.href;
	}
	else { // Search from the bottom of the page up for a next link.
		var els = document.getElementsByTagName("a");
		var i = els.length;
		while ((el = els[--i])) {
			if (el.text.search(/\bnext\b|\bmore[\.…]*$|[>»]$/i) > -1) {
				location = el.href;
				break;
			}
		}
	}
})();

Previous Page

(function() {
	var el = document.querySelector("[rel='prev']");
	if (el) {
		location = el.href;
	}
	else {
		var els = document.getElementsByTagName("a");
		var i = els.length;
		while ((el = els[--i])) {
			if (el.text.search(/\bprev|^[<«]/i) > -1) {
				location = el.href;
				break;
			}
		}
	}
})();

Installation

Save the above scripts to a directory of your choice and add binds to them for example:

# Follow to next page
@bind ]] = script @scripts_dir/go_next_page.js

# Follow to previous page
@bind [[ = script @scripts_dir/go_prev_page.js
 
go-next_prev.txt · Last modified: 2010/01/09 15:14 by 98.222.198.91
 
Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Noncommercial-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki