PDA

View Full Version : Widget Help



gmask1
5th May 2005, 09:31 PM
I have made my very first widget - a simple image switcher, running from my site. It works beautifully in Safari, switching images and all. When I load it in Dashboard, two things happen:
1. It always (100% of the time) loads the first image in the array. Never any others.
2. Once it has loaded the first image the onclick function in the img tag works beautifully until the page refreshes, then it doesn't work at all. In other words, once the first image (which is always the same) is switched out for another image, the onclick call stops working!

Here comes the source for anyone watching - if anyone can help with my two problems, I'd be much obliged:

<head>
<meta http-equiv="Refresh" content="20; url=series1.html">
&#60;script language="JavaScript">
function RandomizeImage()
{
var imagesarray = new Array("http://art.gmaskew.com/widget/s1_img1.jpg", "http://art.gmaskew.com/widget/s1_img2.jpg", "http://art.gmaskew.com/widget/s1_img3.jpg", "http://art.gmaskew.com/widget/s1_img4.jpg", "http://art.gmaskew.com/widget/s1_img5.jpg", "http://art.gmaskew.com/widget/s1_img6.jpg", "http://art.gmaskew.com/widget/s1_img7.jpg")
var randomnumber = Math.round(Math.random()*(imagesarray.length - 1))
document.images.mainlogo.src = imagesarray[randomnumber]
}
</script>
</head>

<html>
<body marginheight="0" marginwidth="0" onLoad="RandomizeImage();">
<img alt="HOME" name="mainlogo" width="323" height="216" id="mainlogo" onclick="widget.openURL(&#39;http://art.gmaskew.com&#39;)">
</body>
</html>

MizuInOz
5th May 2005, 09:41 PM
Hey...

this is what I got for syntax when I loaded it into BBEdit...

File "untitled text"; Line 1: Document must begin with a DOCTYPE to be valid; checker will assume “HTML 4.01 Transitional”.
File "untitled text"; Line 1: Optional open tag for element “<HTML>” not specified.
File "untitled text"; Line 3: Element “&#60;script>” requires that the attribute “type” be specified.
File "untitled text"; Line 13: Document type does not permit element “<html>” in content of element “<html>”.
File "untitled text"; Line 14: Document type doesn&#39;t permit attribute “marginheight” within element “<body>”.
File "untitled text"; Line 14: Document type doesn&#39;t permit attribute “marginwidth” within element “<body>”.
File "untitled text"; Line 15: Element “<img>” requires that the attribute “src” be specified.
File "untitled text"; Line 17: Element “<html>” implicitly closed here.

have you run it in Quartz Composer?
I am just "learning" to build Widgets... would love to see a forum here regarding basics and advanced...

I realize this is a java scripted process but some of the BBEdit may help...
Cheers

:ph34r:

EDIT: BY the way:
there is a Technical Note TN2139 (http://developer.apple.cam/technotes/tn2005/tn2139.html) that may help you, too....

iSlayer
6th May 2005, 11:12 AM
Originally posted by gmask1@May 5 2005, 10:31 PM
<head>
<meta http-equiv="Refresh" content="20; url=series1.html">
&#60;script language="JavaScript">
function RandomizeImage()
{
var imagesarray = new Array("http://art.gmaskew.com/widget/s1_img1.jpg", "http://art.gmaskew.com/widget/s1_img2.jpg", "http://art.gmaskew.com/widget/s1_img3.jpg", "http://art.gmaskew.com/widget/s1_img4.jpg", "http://art.gmaskew.com/widget/s1_img5.jpg", "http://art.gmaskew.com/widget/s1_img6.jpg", "http://art.gmaskew.com/widget/s1_img7.jpg")
var randomnumber = Math.round(Math.random()*(imagesarray.length - 1))
document.images.mainlogo.src = imagesarray[randomnumber]
}
</script>
</head>


<body marginheight="0" marginwidth="0" onLoad="RandomizeImage();">
<img alt="HOME" name="mainlogo" width="323" height="216" id="mainlogo" onclick="widget.openURL(&#39;http://art.gmaskew.com&#39;)">
</body>
</html>
a few things i would do.....

&#60;script>
function RandomizeImage()
{
var imagesarray = new Array("http://art.gmaskew.com/widget/s1_img1.jpg", "http://art.gmaskew.com/widget/s1_img2.jpg", "http://art.gmaskew.com/widget/s1_img3.jpg", "http://art.gmaskew.com/widget/s1_img4.jpg", "http://art.gmaskew.com/widget/s1_img5.jpg", "http://art.gmaskew.com/widget/s1_img6.jpg", "http://art.gmaskew.com/widget/s1_img7.jpg")
var randomnumber = Math.round(Math.random()*(imagesarray.length - 1))
document.getElementById("mainlogo").src = imagesarray[randomnumber]
setTimeout("RandomizeImage()",20000);
}
</script>

<body marginheight="0" marginwidth="0" onload="RandomizeImage();">
<img alt="HOME" name="mainlogo" width="323" height="216" id="mainlogo" onclick="widget.openURL(&#39;http://art.gmaskew.com&#39;)">
</body>


Just simplifying and being picky :)

sikosis
6th May 2005, 11:49 AM
even pickier ... make sure your w3c compliant by specifying the script language ...

&#60;script language="">

iSlayer
6th May 2005, 11:57 AM
wont effect the widget one bit but sure you can if you want.