GM.getResourceUrl: Difference between revisions
From GreaseSpot Wiki
Jump to navigationJump to search
m eliminate category dupe |
→Returns: note about double-encoding |
||
Line 23: | Line 23: | ||
Note: This can be used anywhere a <code>data:</code> URI will work (E.G. <code><img></code> or <code><script></code>). | Note: This can be used anywhere a <code>data:</code> URI will work (E.G. <code><img></code> or <code><script></code>). | ||
This does not include <code><object></code> or <code><embed></code>. | This does not include <code><object></code> or <code><embed></code>. | ||
<!-- A better reference for the reason for the double encoding would be awesome. --> | |||
The result is a base64 encoded URI, which is then also URI encoded, as [http://en.wikipedia.org/wiki/Base64#URL_applications suggested by Wikipedia], because of "+" and "/" characters in the base64 alphabet. | |||
Thus, for certain usage, this URI encoding may need to be removed. | |||
[http://github.com/greasemonkey/greasemonkey/issues/issue/1151] | |||
=== Raises === | === Raises === |
Revision as of 16:58, 4 July 2010
Description
Given a defined @resource, this method returns it as a URL.
Compatibility: Greasemonkey 0.8.0+
Syntax
function GM_getResourceURL( resourceName )
Arguments
resourceName
String
The name provided when the @resource was defined, follow that link for valid naming restrictions.
Returns
String
.
A base64 encoded data:
URI.
Note: This can be used anywhere a data:
URI will work (E.G. <img>
or <script>
).
This does not include <object>
or <embed>
.
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. [1]
Raises
Throws an Error
when the named resource does not exist.
Examples
// ==UserScript== // @resource logo http://www.example.com/logo.png // ==/UserScript== var img = document.createElement('img'); img.src = GM_getResourceURL("logo"); document.body.appendChild(img);