views:

22

answers:

1

This gadget:

<!DOCTYPE html>
<html>

<head>
    <title>Test</title>
    <style type="text/css">
        body
        {
            margin: 0;
            width: 200px;
            height: 200px;
        }
    </style>
    <script type="text/jscript" language="jscript">
        document.onreadystatechange = function()
        {
            System.Gadget.background = "images\\blank.png";  
            someText = gBackground.addTextObject("Some text", "Arial", 12, "Black", 0, 0);
        }
    </script>
</head>

<body>
    <g:background id="gBackground" style="width:100%; height:100%" />
</body>

</html>

Once put onto my desktop, the gadget shows up with a white background (blank.png is just a completely white image), but no text appears. Adding text like so works:

<g:background .......>Text here</g:background>

Does anyone have any ideas as to what I'm doing wrong?

What I've tried:

  1. Change <script type="text/javascript"> to what you see
  2. Change <body onload="init()"> and function init() into what you see
  3. margin: 0;
A: 

I would avoid the use of both System.Gadget.background and g:background and stick to the latter on its own.

  • Make sure to supply the src attribute to the g:background element.
  • Use window.onload instead of document.onreadystatechange, or simply move your script to just before the body tag is closed.
  • Avoid use of the language attribute.

The following works just fine for me:

<!DOCTYPE html>
<html>

    <head>
        <title>Test</title>
        <style type="text/css">
            body
            {
                margin: 0;
                width: 200px;
                height: 200px;
            }
        </style>
        <script type="text/javascript">
            window.onload = function() {
                someText = gBackground.addTextObject("Some text", "Arial", 12, "Black", 0, 0);
            }
        </script>
    </head>

    <body>
        <g:background id="gBackground" src="images/blank.png" style="width:100%; height:100%" />
    </body>

</html>
Andy E
Using that creates an invisible gadget for me.
a2h
@a2h: that's odd. This exact code works fine on my Windows 7 machine. Are you sure your png is white and not transparent?
Andy E
@Andy E - Yep. Here's the source: http://cl.ly/32nI
a2h