W3Schools.com

History go() Method

History Object Reference History Object

Definition and Usage

The go() method loads a specific URL from the history list.

The parameter can either be a number which goes to the URL within the specific position (-1 goes back one page, 1 goes forward one page), or a string. The string must be a partial or full URL, and the function will go to the first URL that matches the string.

Syntax

history.go(number|URL)


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The go() method is supported in all major browsers.


Example

Example

Click on the button to go back two pages:

<html>
<head>
<script type="text/javascript">
function goBack()
  {
  window.history.go(-2)
  }
</script>
</head>
<body>

<input type="button" value="Go back 2 pages" onclick="goBack()" />

</body>
</html>

The output of the code above will be:


Try it yourself »


History Object Reference History Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE