GM.getResourceUrl: Difference between revisions

From GreaseSpot Wiki
Jump to navigationJump to search
(simplify)
(Added a "see also" link to GM_getResourceText)
Line 39: Line 39:
document.body.appendChild(img);
document.body.appendChild(img);
</pre>
</pre>
== See Also ==
* [[GM_getResourceText]]
[[Category:API_Reference|G]]


[[Category:API_Reference|G]]
[[Category:API_Reference|G]]

Revision as of 20:08, 8 June 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>.

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);

See Also