Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Design

Adding a link to an image

Author Message
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Fri Aug 10, 2007 - 5:12 pm    Post subject: Adding a link to an image Reply with quote

I'm creating a News widget that gets the headline from a local newspaper website. On the backside, a sponsorship logo that links to a website. I've set the widget up and everything works fine.

The sponsorship may change every few months, so I have a folder on there server with the logo in it which the widget fulls from. The problem I'm having is how to set it up so the logo links to a website that is company relivant. A new sponsor one month links to their site, next month new sponsor that links to their site.

I set up a javscript that the sponsor DIV links to instead of an image that links to the site works but instead of the widget opening a browser window, it displays the site in the widget.

Here is the javascript:
document.write('<a href="http://www.inskip.com/"><img src="http://www.discoverbristol.com/NewsfeedSponsors/Logo.png"></a>');

Any help would be great.
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Sat Aug 11, 2007 - 10:25 am    Post subject: You need widget.openURL Reply with quote

Hi,

you can't use the link directly but you have to use "widget.openURL". The string you write would have to look something like this:

<a href="javascript:widget.openURL('http://www.example.com')">your image here</a>

The function opens the link within the standard-browser


Hope this helps,

Stephan

PS: I think, in your case you need something like this:

document.write('<a href="javascript:widget.openURL(\"http://www.inskip.com/\")"><img src="http://www.discoverbristol.com/NewsfeedSponsors/Logo.png"></a>');
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Sat Aug 11, 2007 - 1:37 pm    Post subject: Thanks Reply with quote

Thanks for the reply but it didn't work. The logo is clickable but when you click it, nothing happens

Could you use widget.openURL(<Javascript in here>) in the html, then have a the javascript open the link?
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Sat Aug 11, 2007 - 3:06 pm    Post subject: Reply with quote

Hi again,

it did not work because the quotes where set wrong (should've tested it before posting... Smile Try this one:

document.write('<a href=\'javascript:widget.openURL("http://www.inskip.com/")\'><img src="http://www.discoverbristol.com/NewsfeedSponsors/Logo.png"></a>');

btw: You can check how the whole statement looks if you replace "document.write" with "alert". The string should be printed within the Console-App (within the OSX-utilities-folder, just in case you didn't know that already).

Greetings,

Stephan
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Sat Aug 11, 2007 - 3:52 pm    Post subject: Thanks Reply with quote

Thanks Stephan,

It worked.


Thanks again
View user's profile Send private message Send e-mail Widgets
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Mon Aug 13, 2007 - 8:42 am    Post subject: How to clear prefs Reply with quote

It works now but if you change the link thats in the javascript on the server, the widget still remembers the original link.

How can you clear the prefs on a set interval? Maybe once a day the prefs are clear so if the link changes, the widget won't still be linking to the old one.

Thanks
View user's profile Send private message Send e-mail Widgets
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Mon Aug 13, 2007 - 9:05 am    Post subject: Reply with quote

I meant cache. Can you clear the cache for the widget at a set interval.

Any help would be great.

Thanks
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Mon Aug 13, 2007 - 3:14 pm    Post subject: Reply with quote

Jay wrote:
I meant cache. Can you clear the cache for the widget at a set interval.


As I understand it, what you want to do is to update the image on the backside from time to time. First, I don't know if there's a way to clear the cache. Second, I think you'd have to somehow reload the whole widget to get the updated logo.
A simple solution could be to just change the img.src-attribute each time the user switches to the backside. But that would probably mean unnecessary data to be sent each time the user switches to the backside.
So, another solution could be to set an interval (as you suggested) that either changes the img.scr-attribute after a given amount of time or replaces the whole img-tag if the first method doesn't update the logo.

To set an interval you use something like this (calling "updateLogoLink" after 24 hours, the time is in milliseconds):

Code:
setInterval("updateLogoLink();", 24*60*60*1000);


To manipulate the img-tag it is probably best to give in an ID, like "logoImage" for example. You could write the function like this:
Code:

function updateLogoLink(){
   document.getElementById("logoImage").src = "";
   document.getElementById("logoImage").src = "LinkToLogo";
}


Note: I didn't test that, but only wrote it down as I usually change attributes in my widgets. So of it doesn't work, just mail back. And another thing: I am not sure if the img is updated if you just provide the same link that is already in the src-attribute, therefore I first set it to an empty string. You can try if it works without the first src-change, too.

Greetings,

Stephan
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
Jay



Joined: 05 Jan 2007
Posts: 13

Posted: Mon Aug 13, 2007 - 6:34 pm    Post subject: Reply with quote

Thanks Stephan,

I found that once you restart, the cache is clear and the widget will display the new logo and link. I have the widget pulling the javascript from a webserver which also houses the logo.

I was going to have it clear cache or update once or twice a day, but I'm happy with it changing when you restart or turn the computer on and I won't have to write more code. I can keep it nice and simple. I've tested it on a few computers all day and it works.

Thanks again for all your help.
View user's profile Send private message Send e-mail Widgets
aamann



Joined: 27 Dec 2006
Posts: 5

Posted: Mon Aug 13, 2007 - 7:08 pm    Post subject: no need to restart! Reply with quote

There is an easier way to force an update and not use the cached version - simply append "?someRandomText" (without the quotes) to the source URL - the easiest one to add would be "new Date().getTime()" (which will give you the current time in seconds.

As the "new URL" now is different from the original one (and the web server will most likely simply ignore the query string) you will download a new, un-cached version if the image.
View user's profile Send private message Send e-mail Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group