Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:51:34+00:00 2026-06-16T20:51:34+00:00

I need to load cross-domain JavaScript files dynamically for bookmarklets in my site http://jsbookmarklets.com/

  • 0

I need to load cross-domain JavaScript

files dynamically for bookmarklets in my site http://jsbookmarklets.com/

The solution should satisfy:

  • Fetch the path of current file
  • The domain of current web-page and JS file in execution are different
  • The solution should be cross-browser
  • Multiple scripts might be loaded at once asynchronously (that’s why the related questions mentioned below are not a fit)

I want to get the file path of currently executing JavaScript code for dynamically loading few more resources (more CSS files and JS files like custom code and jQuery, jQuery UI and Ext JS libraries) which are stored in the same/relative folder as the JavaScript Bookmarklet.

The following approach does not fit my problem:

var scripts = document.getElementsByTagName("script");
var src = scripts[scripts.length-1].src;
alert("THIS IS: "+src);

Related questions which do not fit my problem:

  • Get the url of currently executing js file when dynamically loaded
  • Get script path
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:51:35+00:00Added an answer on June 16, 2026 at 8:51 pm

    The current solution that I’m using, which works, but is very lengthy:

    var fnFullFilePathToFileParentPath = function(JSFullFilePath){
        var JSFileParentPath = '';
        if(JSFullFilePath) {
            JSFileParentPath = JSFullFilePath.substring(0,JSFullFilePath.lastIndexOf('/')+1);
        } else {
            JSFileParentPath = null;
        }
        return JSFileParentPath;
    };
    
    var fnExceptionToFullFilePath = function(e){
        var JSFullFilePath = '';
    
        if(e.fileName) {    // firefox
            JSFullFilePath = e.fileName;
        } else if (e.stacktrace) {  // opera
            var tempStackTrace = e.stacktrace;
            tempStackTrace = tempStackTrace.substr(tempStackTrace.indexOf('http'));
            tempStackTrace = tempStackTrace.substr(0,tempStackTrace.indexOf('Dummy Exception'));
            tempStackTrace = tempStackTrace.substr(0,tempStackTrace.lastIndexOf(':'));
            JSFullFilePath = tempStackTrace;
        } else if (e.stack) {   // firefox, opera, chrome
            (function(){
                var str = e.stack;
                var tempStr = str;
    
                var strProtocolSeparator = '://';
                var idxProtocolSeparator = tempStr.indexOf(strProtocolSeparator)+strProtocolSeparator.length;
    
                var tempStr = tempStr.substr(idxProtocolSeparator);
                if(tempStr.charAt(0)=='/') {
                    tempStr = tempStr.substr(1);
                    idxProtocolSeparator++;
                }
    
                var idxHostSeparator = tempStr.indexOf('/');
                tempStr = tempStr.substr(tempStr.indexOf('/'));
    
                var idxFileNameEndSeparator = tempStr.indexOf(':');
                var finalStr = (str.substr(0,idxProtocolSeparator + idxHostSeparator + idxFileNameEndSeparator));
                finalStr = finalStr.substr(finalStr.indexOf('http'));
                JSFullFilePath = finalStr;
            }());
        } else {    // internet explorer
            JSFullFilePath = null;
        }
    
        return JSFullFilePath;
    };
    
    var fnExceptionToFileParentPath = function(e){
        return fnFullFilePathToFileParentPath(fnExceptionToFullFilePath(e));
    };
    
    var fnGetJSFileParentPath = function() {
        try {
            throw new Error('Dummy Exception');
        } catch (e) {
            return fnExceptionToFileParentPath(e);
        }
    };
    
    var JSFileParentPath = fnGetJSFileParentPath();
    alert('File parent path: ' + JSFileParentPath);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: JQuery ajax cross domain I need to load content from another websites
I need to load some js files dynamically and sequentially(i.e. second script loads after
I'm trying to better understand Cross Site Scripting and lets use: http://api.beatport.com/crossdomain.xml as the
So I need to make a a cross domain request where the response is
I am making a cross-domain JSON(P) call by using JavaScript to add a <script>
I am in need a cross-browser jQuery solution for revealing elements on a HTML
I need to load a bunch of CSS files through ajax and call an
I need to resize cross domain iframe to fit content . So in parent.html
All, I'm trying to load a cross-domain policy file from a custom location (instead
I need to load a Model in a component to save the Data of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.