Redirect to another page

Navigate to a URL, adding an entry to the history.

JavaScriptBrowser · DOM Version 1.0.0 · MIT · .md

redirect-to-another-page.js
function goTo(url) { location.assign(url); }

Usage

usage.js
goTo('#pricing');
location.hash; // → '#pricing'

Lines marked → were executed in headless Chromium against the markup above, and each result was compared with the value shown. Lines marked e.g. are illustrative.

Know the limits

  • A URL taken from user input is an open redirect, and a javascript: URL runs code. Accept only relative paths or an allow-list of origins.
  • location.assign adds a history entry; location.replace does not. The test uses a fragment, which navigates within the page.

The function above is the code the usage lines run. It does not validate its arguments; add checks where it receives untrusted input.

Source & maintenance

Based on Redirect to another page from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Uses location.assign; open-redirect and javascript: URL risks documented. Executed in Chromium with a fragment URL. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Usage lines executed in headless Chromium against the fixture markup; no external services · reviewed October 28, 2026.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.