Extracting a Shared Box URL from the Login Page

Published: (January 19, 2026 at 05:23 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

When you open a Box file link on Windows, the browser may redirect you to the Box login page instead of taking you directly to the shared content. Often the login page URL includes a query parameter that contains the original destination. This snippet extracts that destination URL and copies it to your clipboard, letting you quickly recover the share‑ready link.

JavaScript snippet

(function () {
  const hostOrig = location.host;

  // Skip if host does not end with box.com
  if (!hostOrig.endsWith('box.com')) return;

  const usp = new URLSearchParams(location.search);
  const path = usp.get('redirect_url');

  // Skip if redirect_url is missing or empty
  if (!path) return;

  const host = hostOrig
    .split('.')
    .filter((part) => part !== 'account')
    .join('.');

  // If redirect_url is an absolute URL, use it as‑is; otherwise build https://{host}{path}
  const url = 'https://' + host + path;

  const tempTextarea = document.createElement('textarea');
  tempTextarea.textContent = url;
  document.body.appendChild(tempTextarea);
  tempTextarea.select();
  document.execCommand('copy');
  document.body.removeChild(tempTextarea);
})();

Bookmarklet

javascript:!function(){const hostOrig=location.host;if(!hostOrig.endsWith("box.com"))return;const path=new URLSearchParams(location.search).get("redirect_url");if(!path)return;const url="https://"+hostOrig.split(".").filter(part=>"account"!==part).join(".")+path;const tempTextarea=document.createElement("textarea");tempTextarea.textContent=url;document.body.appendChild(tempTextarea);tempTextarea.select();document.execCommand("copy");document.body.removeChild(tempTextarea)}();

How it works

  • Parse the query string using URLSearchParams to read parameters on the current page.
  • Extract redirect_url to obtain the path (or full redirect target) that Box stored when it sent you to the login flow.
  • Rebuild the host name by removing the account subdomain (common on Box login pages) so the destination points to the main Box domain.
  • Construct the final URL by combining https://, the adjusted host, and the redirect path.
  • Copy the result to the clipboard by temporarily creating a <textarea>, selecting its contents, and executing the copy command.
  • Clean up by removing the temporary element from the page.

Using this approach, you can recover a share‑ready URL directly from the Box login screen without manually decoding or editing the address bar.

Back to Blog

Related posts

Read more »

Bootstrapping Bun

Article URL: https://walters.app/blog/bootstrapping-bun Comments URL: https://news.ycombinator.com/item?id=46681309 Points: 3 Comments: 0...

Fundamentals of react app

Introduction Today we’re going to look at the reasons and uses of the files and folders that are visible when creating a React app. !React app structurehttps:/...