Referencing images relatively?

Hi!

Is there a way, to reference images relatively I mean, I want to use pictures in the my gadget, wich are next to the gadget.xml, so i want to use relative path to them.

My idea is the the following:
According to the developer's guide external items can be defined, and used from code with a name. In the gadget.xml I can use relative path. And all this works pretty well for external xml files. Like the 'quotes' example. But is there a way to do the same with images





Answer this question

Referencing images relatively?

  • Blackwood

    Yes. Use the Module class's "resolveUrl()" method to resolve a relative url. This is necessary because gadgets don't run on the same domain they're hosted, so URLs aren't actually relative to the location of the gadget code. Module.resolveUrl() will turn a relative URL into a complete URL by prepending the gadget's host location.

    Let's say I have an image "images/foo.gif", relative to my gadget.xml manifest. If I want to stuff that into an Image object or an IMG element, I can do the following:

    var img = new Image();
    img.src = m_module.resolveUrl("images/foo.gif");

    Assume that m_module is a variable I set earlier to reference p_args.module.

    More information is available in the SDK.


  • Referencing images relatively?