[SalesForce] How to get page’s static resource URL string using JavaScript code

I want to get URL string of Salesforce static resource in JavaScript code.

Something like:

var url = getURL('static_resource_name')

Is there a method to capture this from a page using JS?

Best Answer

You can use html input hidden tag as:

<input type="hidden" id="stresource" value="{!$Resource.staticResourceName}"/>


    var resource_url = document.getElementById('stresource').value;

    // direct way:
    var diret_url = '{!$Resource.staticResourceName}';