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

Trying to fix a bug in my widget - page refresh

Author Message
bifter



Joined: 31 Jul 2006
Posts: 4

Posted: Fri Oct 17, 2008 - 8:57 am    Post subject: Trying to fix a bug in my widget - page refresh Reply with quote

I've decided to get stuck back into a widget I started 2 years ago! Wow where did the time go?

Anyway, it seems it was very nearly finished - I just a have few bugs to iron out.

Here's the first one I can't seem to fix.

I have various divs that display depending on the prefs that have been set. In one div the user clicks on some text to set a pref.

Once the pref is set it will change the div that is displayed. However, I tried to do this by using

Code:
window.location.reload();


but it doesn't seem to work right - in fact the widget just disapears. When I refresh (in the area where the widget was) it does the swirly thing and appears as it should.

My question is how can I refresh the page the same time the pref is set?

Here is the code I have so far in case it helps.

Code in HTML

Code:
<a href="#" onclick="iFailed()">I FAILED</a>


Script

Code:
<!-- When user clicks I FAILED take them to the failure div and write a failure cookie -->
function iFailed(){
   widget.setPreferenceForKey("yes","failure");
   window.location.reload();
}


When the page refreshes it runs a script that will detect that failure=yes and shows the correct page.

Code:
if(widget.preferenceForKey('failure') != null){
   document.getElementById('iFailedPage').style.display = 'block'; etc etc


I'm sure it's simple but I think i'm getting too tired to fix any help would be greatly appreciated Smile Thanks.
View user's profile Send private message Send e-mail Widgets
bifter



Joined: 31 Jul 2006
Posts: 4

Posted: Fri Oct 17, 2008 - 9:22 am    Post subject: Reply with quote

Aha, I've a very bad habit of fixing stuff just after I've put a post on a forum!

Writing it all down made me look at the problem from a different angle. Instead I run two functions from the onclick like this...

Code:
function doThisFirst() {
  alert("Changing current location")
}

function doThisNext()  {
   location.href="myotherpage.html"
}
 
function doThese() {
   doThisFirst()
   doThisNext()
}

<a href="javascript:null()" onClick="doThese()"><img src="image.jpg"></a>

You can have as many events as you like here, but it can get a little
messy.

Alternatively you can have :

<a href="javascript:null()" onClick="doThisFirst();doThisNext()"><img
src="image.jpg"></a>
The semi-colon separates the function calls.
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