1

Can anyone recommend the easiest way to toggle the display of an element remotely? I won't have access to the server so I was wondering if there is a way to remotely toggle the display of an element, in this case from solid to faded? I'm using dashcode and I don't know how cross domain policy impacts this.

   $(document).ready(function(hideStuff) {
   $('.image2_template').css({ 'opacity' : 0.1 });
   $('.text3_template').css({ 'opacity' : 0.1 });
davis
  • 1,911
  • 6
  • 26
  • 50
  • What do you mean by "toggle... remotely?" – Matt Ball Aug 02 '11 at 19:37
  • so... if i publish this website i'm not going to have access to the server, but is there a way to show or hide the element by setting a value from a remote server? If that makes sense, I'm new to this. – davis Aug 02 '11 at 19:42
  • Doesn't really make sense to me, though it sounds like you'll use some sort of ajax. Check out "ajax push" or "reverse ajax," specifically implemented through "long polling" or "comet." – Matt Ball Aug 02 '11 at 20:25

1 Answers1

1

I’m doing the same sort of thing in a Dashcode widget… I have a version.js file on the widget’s website, and if that file reports a newer version number than what the user’s using, they’ll see a prompt to update. What I did was basically this:

  1. Set the element to its default state (“solid” for you, I guess) as your widget initializes.
  2. Using an AJAX query, get the JSON file from the server. (You can do this easily with jQuery.)
  3. In the callback function for the AJAX query, check whatever you need to; if your display needs to change, then go ahead and do

    document.getElementById("image2_template").style.setProperty("opacity", 0.1);
    

    or whatever you need to do.

Note that you will need access to some server somewhere in order for this to work.

bdesham
  • 15,430
  • 13
  • 79
  • 123
  • I'm still having trouble with this. I think I need to find a web host who allows requests from a different domain. I keep getting data that is undefined. – davis Aug 11 '11 at 00:46
  • Allowing requests from anywhere is the standard behavior for any web host or server. What exactly are you trying to do? – bdesham Aug 12 '11 at 02:18