Dashcode Question...

qbkd10

Registered
Would it be possible, in Dashcode for Leopard, to create a glass button on a widget to be linked to a URL?

Thanks in advance.

~Qbkd10
 
Yes, just add an "onClick" event to the button, then have the onClick call the following function:
Code:
function openURL()
{
  if ( window.widget )
  {
    widget.openURL( “http://www.google.com” );
    return false;
  }
}
...replacing "http://www.google.com" with whatever web address you want.
 
Wait... wait... wait. Did some more ADC research and found that this works:

Code:
    function openURL(section)
    {
        if (widget)
        {
            widget.openURL('http://www.quinnyblog.com' + section);
        }
    }

...when put into the [WidgetName].js file at the bottom. To avoid confusion, you can replace openURL with whatever you want, even elDiablo! Just make sure to link your button back up.

EDIT: Now, the button is adding some stuff to the end of the URL, anyone that can help me with that?
DOUBLE EDIT: Woo woo! Sorry, but I may sound like a complete idiot. I got it to work! This line of code:
Code:
        {
            widget.openURL('http://www.quinnyblog.com' + section);
        }
... can be replaced with:
Code:
        {
            widget.openURL('http://www.quinnyblog.com');
        }
It's easier than i originally thought! That little strip of code can be so pesky. What does it mean by + section, anyway?
 
"+ section" just adds the value of the variable "section" to the end of the URL.

So, for example, if you had this somewhere prior to the function:
Code:
var section = "/somesite.html"
Then, the variable "section" would evaluate to the text "/somesite.html". Then, when you call the openURL function with:
Code:
widget.openURL('http://www.quinnyblog.com' + section)
...you would actually be opening the URL "http://www.quinnyblog.com/somesite.html"

The + operator simply concatenates the two strings together. You have one string, explicitly defined as "http://www.quinnyblog.com" and another string, defined in the variable "section." When you "plus" or "add" them together as in the code examples, you're simply concatenating the two together to make one, long string... the same as simply calling:
Code:
openURL('http://www.quinnyblog.com/somesite.html')
You could also store the WHOLE string as a variable, or as multiple variables. You could do this:
Code:
var first = 'http://'
var second = 'www.yo-i-am-the-coolest-ever.com'
var third = '/you-better-believe-it.html'

openURL(first + second + third)
...and the openURL function would basically be this:
Code:
openURL('http://www.yo-i-am-the-coolest-ever.com/you-better-believe-it.html')

Make sense? :)
 
Yep, so the variable "section" is getting set to either "/index.html" or "/games.html" somewhere in the code prior to the openURL function getting called.

I'm not sure I understand "you should use variables when you have multiple buttons linking to the same site" -- are you sure you don't mean the opposite, which would be using ONE button to link to multiple sites? You could use a variable called "link" and do this:
Code:
widget.openURL(link)
...and then, before you call that, you could set the variable "link" to wherever you wanted to go. Say a person using your widget wanted to visit one of two sites: either apple.com or microsoft.com. Depending on which they wanted, you could either set the variable "link" to "http://www.apple.com" or "http://www.microsoft.com", then just call "openURL(link)" and it would go to whatever site the variable "link" was storing.
 
Back
Top