Extracting a Shared Box URL from the Login Page
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
URLSearchParamsto read parameters on the current page. - Extract
redirect_urlto 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
accountsubdomain (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.