Greasemonkey - Image not shown

In Greasemonkey, I am trying to use a local copy of an image found on the Internet. The image is temporarily stored in the C: \ temp folder.

This does not work:

var b = document.body;
b.style.background = '#ccc url("file:///C:/temp/bg.jpg") repeat-x top left';

In Firebug, I can hover over a path in the style window, and the image will pop up, showing that the image is there and that the path is correct, but Firefox just doesn't display it. I even tried redrawing the page:

  setTimeout(function(){element.className = element.className;},500);

If I use the path to the original http URL (http: //somedomain/bg.jpg), it will work, but tries to avoid it. I'm not sure why he has problems rendering local images.

+3
source share
5 answers

Greasemonkey (, , gazillions , ).

:

  • Greasemonkey (Ctrl Shift A), script, .

  • , script , script .

    , script C:\myScripts\, bg.jpg . script.

  • script:

    // @resource MyBG_Image bg.jpg
    // @grant    GM_getResourceURL
    
  • script:

    var b = document.body;
    b.style.background = '#ccc url("' + GM_getResourceURL ("MyBG_Image") + '") repeat-x top left';
    
  • script, Firefox. , FF File- > Open File ( Ctrl O), C:\myScripts\MyScript.user.js
    Greasemonkey () script, bg.

+8

, (://) , .

. ( , )

. : URI.

+2

. script (re), .

:

    // @resource MyTest_Image animated_gif_test.gif

script GM

    //images[x].src  = GM_getResourceURL ("MyTest_Image");

: http://wiki.greasespot.net/GM_getResourceURL

    // ==UserScript==
    // @resource logo http://www.example.com/logo.png
    // ==/UserScript==

    var img = document.createElement('img');
    img.src = GM_getResourceURL("logo");
    document.body.appendChild(img);
+1

, ...

// @grant       GM_getResourceURL
+1

: http://www-archive.mozilla.org/releases/mozilla1.7.12/known-issues.html

  

Mozilla - . , : . url :///- javascript. , , -. , user.js . user_pref ( "security.checkloaduri", false); ( 84128)

  
0

All Articles