swn78

Hello, 2 questions:

1. What is the downside of embedding a web page as a gadget In my case Im trying to convert what is originally a web page into a gadget. Is there any reason why I shouldn't just embed a modified web page

2. Im trying to write a simple gadget that contains links, when clicking a link I want to change the displayed information on the gadget. Ive looked at the Quote of the Day example, but that code is a bit over my head... does anyone have an easy to comprehend example (in short I want to be able to make links that doesn't link to a new page but instead changes the information inside of the gadget)



Re: Web Gadget Development embedding and updating content

ToddOs

swn78 wrote:

Hello, 2 questions:

1. What is the downside of embedding a web page as a gadget In my case Im trying to convert what is originally a web page into a gadget. Is there any reason why I shouldn't just embed a modified web page

2. Im trying to write a simple gadget that contains links, when clicking a link I want to change the displayed information on the gadget. Ive looked at the Quote of the Day example, but that code is a bit over my head... does anyone have an easy to comprehend example (in short I want to be able to make links that doesn't link to a new page but instead changes the information inside of the gadget)

  1. Gadgets are intended to be small, discrete, single-purpose little applets. Embedding an entire web page into a gadget is overkill and generally goes against the intent of gadgets. That said, you certainly can do this. I wouldn't really recommend it, though :)
  2. Time to brush up on DHTML and Javascript, especially event handling. What it sounds like you want to do is attach an "onclick" handler for the links and then load/show/hide some data. A good place to start would be the gadget SDK. A word of advice -- if you're going to handle "onclick" for an anchor element (<a />), make sure you return false or the page will navigate to whatever href you've set (typically that will be "#" if you don't want the link to actually go somewhere). There's sample code out there, and you could look at the code behind any gadget up on Gallery if you know how to find it (it's not too difficult to find). As for being "easy to comprehend", that really depends on your familiarity and comfort level working with DHTML, Javascript, and CSS.




Re: Web Gadget Development embedding and updating content

swn78

ToddOs wrote:

  1. [...]
  2. Time to brush up on DHTML and Javascript, especially event handling. What it sounds like you want to do is attach an "onclick" handler for the links and then load/show/hide some data. A good place to start would be the gadget SDK. A word of advice -- if you're going to handle "onclick" for an anchor element (<a />), make sure you return false or the page will navigate to whatever href you've set (typically that will be "#" if you don't want the link to actually go somewhere). There's sample code out there, and you could look at the code behind any gadget up on Gallery if you know how to find it (it's not too difficult to find). As for being "easy to comprehend", that really depends on your familiarity and comfort level working with DHTML, Javascript, and CSS.

Thanks for the reply, Todd.

My problem being in this perticular case is that a Gadget page does not work the same way as a normal DHTML page would. As you said, I did use Javascripts event handling to launch an event when the link was clicked. I've confirmed that the event is really triggered by launching an alert message. This works, but how do I reload the conent which the gadget is displaying

The method I've tried is to set a variable with the html content, this content gets a new value when the link is clicked after which I call window.location.reload... that didnt work.

Ive looked at the code for the Quote of the Day gadget (I think this is one of the standard gadgets )..

The relevant part in this code:

spn.attachEvent("onclick",o);

/.../

function o(p){
q(p.srcElement);
}

/.../

function q(r,s){
if(!r||!r.feedUrl||!r.feedName||!r.channelId)
return;
if(r==m_activeTab)
return;
if(m_activeTab)
m_activeTab.className=
"Tab Channel"+m_activeTab.feedName;
m_activeTab=r;
m_activeTab.className=
"Tab_Current Channel"+m_activeTab.feedName;
if(!s)
B();
Start.RssManager.fetchFeed(m_baseFeedUrl+m_activeTab.feedUrl,Start.RssManager.MAX_ITEMS,t);
}

And my code:

function onclick()
{
alert("Change content");
}

/.../

function getLink(src, txt, page)
{
var newlink = document.createElement("a");
newlink.innerText = txt;
newlink.href = src;
newlink.attachEvent(
"onclick",onclick);
}

The above code generates a link which does launch an event, but I cant figure out how to reload/change content on the gadget page itself. On a normal web page I could just redirect the user to another page, but what am I supposed to do in this case Any suggestions appreciated.





Re: Web Gadget Development embedding and updating content

Marijke S

I 'd suggest that you put your different contents in different divs.
Like with normal webpages you make another page.

Then you can use removeChild and appendChild to change the content of your gadget.
Something like:

function SwichContent()
{
        if (m_el.appendChild(divA))
        { 
              m_el.removeChild(divA);
              m_el.appendChild(divB);
        }
        else
        {
             return null;
        }
}

 






Re: Web Gadget Development embedding and updating content

swn78

Thanks Marijke, it was helpful.