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 Development

Yet another .openURL() question!

Author Message
superlukeyboy



Joined: 18 Jun 2007
Posts: 2

Posted: Mon Jun 18, 2007 - 9:41 am    Post subject: Yet another .openURL() question! Reply with quote

I am making a widget that will sit on my desktop (yes im going to bring it out off dashboard) and will launch my applications and urls when i type what i want.

Basically, if i type 'facebook' it will go to the facebook website, if i type 'music' it will open iTunes.
I've got most of the code working, I'm just struggling with the same problem that loads of other people are having. It will open once, but then won't do it again.

Because i want my widget to be on show outside of the dashboard i don't know if there is any point in me having and onshow or onhide function. I'm not sure if the problem is the fact that i use a form and a submit, ive seen a couple of people say that this is a bad move.

Here is my code, see what you all think. Any ideas/suggestions would be great. Notice the comment at the end of my javascript.

Code:
<html>
<head>
<style type="text/css">
   @import "Launcher.css";
</style>
<script type='text/javascript' src='Launcher.js' charset='utf-8'/>
</head>
<body>
   <img src="Images/Background.png">
<form name="Launcher" method="post" onSubmit='testing()'>
   <input name="search" id="search" type="text" value="">
   <input name="submit" id="submit" type="submit" value="Go">
</form>
</body>
</html>


Thats the html and here is the javascript

Code:
function testing()
{
text = document.Launcher.search.value

if (text == "firefox") {
widget.openApplication("org.mozilla.firefox")
}


else if(text == "itunes") {
widget.openApplication("com.apple.iTunes")
}

else if(text == "facebook") {
widget.openURL('http://www.facebook.com')
}

else if(text == "cadets") {
widget.openURL('http://www.2313atc.co.uk/forum')
}

//i was thinking that some sort of refresh/reload code here might work. what do you think?

}


An idea i had would be to insert the code that CMD-R executes? would that work?

thanks in advance everyone!
View user's profile Send private message Send e-mail Widgets
JayHD



Joined: 06 Apr 2007
Posts: 15

Posted: Tue Jun 19, 2007 - 12:15 am    Post subject: Reply with quote

Hey,

There are a few ways to do what you are attempting to do. Here's a solution to the method you are using.

Code:
<html>
<head>
<style type="text/css">
   @import "Launcher.css";
</style>
<script type='text/javascript' src='Launcher.js' charset='utf-8'/>
</head>
<body>
   <img src="Images/Background.png">
   <input name="text" id="launcherText" type="text" value="" onchange="launchAction();">
</body>
</html>


Code:
function launchAction()
{

var launcherText = document.getElementById("launcherText").value

if (launcherText == "firefox")
   widget.openApplication("org.mozilla.firefox")
else if(launcherText == "itunes")
   widget.openApplication("com.apple.iTunes")
else if(launcherText == "facebook")
   widget.openURL('http://www.facebook.com')
else if(launcherText == "cadets")
   widget.openURL('http://www.2313atc.co.uk/forum')
   
launcherText = ""
document.getElementById("launcherText").value = launcherText

}


This way you type in what you want, hit return and it goes. No need for a "Go" button.

If you still want the button, change
Code:
<input name="text" id="launcherText" type="text" value="" onchange="launchAction();">

to
Code:
<input name="text" id="launcherText" type="text" value="">
<input name="button" id="goButton" type="button" value="Go" onclick="launchAction();" >
View user's profile Send private message Send e-mail Widgets
superlukeyboy



Joined: 18 Jun 2007
Posts: 2

Posted: Tue Jun 19, 2007 - 8:20 am    Post subject: Reply with quote

wow thats excellent, thanks a lot! works like a dream.

now if only i could find a way for it to launch on startup and go straight to sitting on the desktop...
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