Skip to content

Instantly share code, notes, and snippets.

@karim23657
Last active January 17, 2023 19:53
Show Gist options
  • Save karim23657/498cbc8e992dd7fbc6c2c67ca43aa448 to your computer and use it in GitHub Desktop.
Save karim23657/498cbc8e992dd7fbc6c2c67ca43aa448 to your computer and use it in GitHub Desktop.

Get script base path fron code

// window.location.pathname.toString().substring(0, window.location.pathname.toString().lastIndexOf('/')) + '/'
document.currentScript.src.toString().substring(0, document.currentScript.src.toString().lastIndexOf('/'))+ '/'

if path of js file is https://cdn.jsdelivr.net/npm/bbb/mmm.js it returns https://cdn.jsdelivr.net/npm/bbb/

function getScriptFileName() {
  return (new Error).fileName;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment