Skip to content
vast-cow's blog
Go back

Extracting a Shared Box URL from the Login Page

Edit page

When you open a Box file link on Windows, your browser may redirect you to the Box login page instead of taking you directly to the shared content. In many cases, the login page URL includes a query parameter that contains the original destination. If you need to quickly recover the shareable link (for example, to send it to someone or open it in another environment), it is useful to extract that destination URL from the login page.

The following JavaScript snippet is designed for that purpose. It reads the current login page URL, retrieves the redirect_url parameter from the query string, reconstructs the full destination URL, and copies it to your clipboard automatically.

(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);
})();
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)}();

Here is what the script does, step by step:

In practice, this provides a quick way to recover a share-ready URL directly from the Box login screen, without manually decoding or editing the address bar.


Edit page
Share this post:

Comments


Previous Post
How to Uninstall Microsoft 365 Office
Next Post
Switching from the ChatGPT Web Page to the ChatGPT App on iOS