Difference between revisions of "GM.getResourceUrl"
(→Returns: greasemonkey-script: protocol)
Revision as of 10:34, 3 November 2017
Given a defined @resource, this method returns it as a URL.
Compatibility: Greasemonkey 0.8.0+
function GM_getResourceURL( resourceName )
StringThe name provided when the @resource was defined, follow that link for valid naming restrictions.
greasemonkey-script:[script uuid]/[resource name]
Prior to Greasemonkey 1.0
Returns string containing a base64 encoded
Note: This can be used anywhere a
data: URI will work (E.G.
This does not include
The result is a base64 encoded URI, which is then also URI encoded, as suggested by Wikipedia, because of "+" and "/" characters in the base64 alphabet. Thus, for certain usage, this URI encoding may need to be removed. 
Error when the named resource does not exist.
// ==UserScript== // @resource logo http://www.example.com/logo.png // ==/UserScript== var img = document.createElement('img'); img.src = GM_getResourceURL("logo"); document.body.appendChild(img);