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

Works in .html, not as .wdgt

Author Message
hammo



Joined: 07 Sep 2007
Posts: 3

Posted: Sat Sep 08, 2007 - 4:22 am    Post subject: Works in .html, not as .wdgt Reply with quote

So I've got a widget that essentially, based on what information you put in, loads a page with details applying to the submitted info.

When I test it as an .html file, it works 100% perfectly, yet when I run it as a widget and click the "search" button, nothing moves.

Is there a certain function I have to call in order to have links open within a widget?

My code is as follows:

wowarmwid.html
Code:
<html>
<head>
<script type="text/javascript" src="gogo.js"></script>
</head>
<body style="margin: 0;">
<form name="search" >
<div style="background: url(Default.png);height: 657;width: 448px;">
   <div style="position: absolute;top: 121px;left: 76px;z-index: 1;">
      <input type="text" name="n" onkeypress="return noenter()" style="width: 301px; height: 21px;border: 0;background-color: #0d0d0d;border-color: #0d0d0d;color: #fddd2f;padding: 2px;" />
   </div>
   <div style="position: absolute;top: 164px;left: 76px;z-index: 1;">
      <select name="r" onkeypress="return noenter()" style="width: 229px; height: 21px;border: 0;border-color: #0d0d0d;background-color: #0d0d0d;color: #fddd2f;">
         <option value="Argent Dawn">Argent Dawn</option>
         <option value="Arthas">Arthas</option>
         <option value="Azgalor">Azgalor</option>
         <option value="Bleeding Hollow">Bleeding Hollow</option>
         <option value="Bloodhoof">Bloodhoof</option>
         <option value="Durotan">Durotan</option>
         <option value="Elune">Elune</option>
         <option value="Lothar">Lothar</option>
         <option value="Madoran">Madoran</option>
         <option value="Magtheridon">Magtheridon</option>
         <option value="Mannoroth">Mannoroth</option>
         <option value="Medivh">Medivh</option>
         <option value="Shattered Hand">Shattered Hand</option>
         <option value="Skullcrusher">Skullcrusher</option>
         <option value="Stormrage">Stormrage</option>
         <option value="Warsong">Warsong</option>
         <option value="Zul'jin">Zul'jin</option>
      </select>
         
   </div>
   <div style="position: absolute;top: 165px;left: 314px;z-index: 1;">
      <img src="blank.png" onclick="makeRequest('')" />
   </div>

   <div style="position: absolute;top: 234px;left: 35px;z-index: 1;">
      <div style="padding: 0; width: 376px; height: 386px; overflow: hidden;">

      </div>
   </div>
</div>
</body>
</html>





gogo.js
Code:
    function clicked(section)
    {
        if (widget)
        {

       var realm = document.search.r.value;

       var name = document.search.n.value;

            widget.openURL('http://wowarmory.com/character-arenateams.xml?r=' + realm + '&n=' + name);

            widget.openURL('http://wowarmory.com/character-sheet.xml?r=' + realm + '&n=' + name);

        }
    }

   function noenter() {
        return !(window.event && window.event.keyCode == 13); }

    function makeRequest(url) {

   var realm = document.search.r.value;

   var name = document.search.n.value;

        url = ('http://wowarmory.com/character-sheet.xml?r=' + realm + '&n=' + name);


        var httpRequest;

            httpRequest = new XMLHttpRequest();
            httpRequest.overrideMimeType('text/xsl');
 
        if (!httpRequest) {
            alert('Giving up :( Cannot create an XMLHTTP instance');
            return false;
        }

        httpRequest.onreadystatechange = function() { alertContents(httpRequest); };
        httpRequest.open('GET', url, true);
        httpRequest.send('');

    }



    function alertContents(httpRequest) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {

      var string = httpRequest.responseText;
      
      string = string.replace(/img src=\"/gi,"img src=\"http://wowarmory.com/");
      string = string.replace(/script src=\"/gi,"script src=\"http://wowarmory.com/");
      string = string.replace(/css\//gi,"file:///Users/hammo/Documents/armwdgtcss/");

      var stringin = " <html> \n"
      stringin = stringin + "<head> \n"
      stringin = stringin + "<script type=\"text/javascript\" src=\"gogo.js\"></script> \n"
      stringin = stringin + "</head> \n"
      stringin = stringin + "<body style=\"margin: 0; background: white;\"> \n"
      stringin = stringin + "<form name=\"search\" > \n"
      stringin = stringin + "<div style=\"background: url(Default.png);height: 657;width: 448px;\">\n"
      stringin = stringin + "   <div style=\"position: absolute;top: 121px;left: 76px;z-index: 1;\">\n"
      stringin = stringin + "      <input type=\"text\" name=\"n\" onkeypress=\"return noenter()\" style=\"width: 301px; height: 21px;border: 0;background-color: #0d0d0d;border-color: #0d0d0d;color: #fddd2f;padding: 2px;\" />\n"
      stringin = stringin + "   </div>\n"
      stringin = stringin + "   <div style=\"position: absolute;top: 164px;left: 76px;z-index: 1;\">\n"
      stringin = stringin + "      <select name=\"r\" onkeypress=\"return noenter()\" style=\"width: 229px; height: 21px;border: 0;border-color: #0d0d0d;background-color: #0d0d0d;color: #fddd2f;\">\n"
      tringin = stringin + "         <option value=\"Argent Dawn\">Argent Dawn</option>\n"
      stringin = stringin + "         <option value=\"Arthas\">Arthas</option>\n"
      stringin = stringin + "         <option value=\"Azgalor\">Azgalor</option>\n"
      stringin = stringin + "         <option value=\"Bleeding Hollow\">Bleeding Hollow</option>\n"
      stringin = stringin + "         <option value=\"Bloodhoof\">Bloodhoof</option>\n"
      stringin = stringin + "         <option value=\"Durotan\">Durotan</option>\n"
      stringin = stringin + "         <option value=\"Elune\">Elune</option>\n"
      stringin = stringin + "         <option value=\"Lothar\">Lothar</option>\n"
      stringin = stringin + "         <option value=\"Madoran\">Madoran</option>\n"
      stringin = stringin + "         <option value=\"Magtheridon\">Magtheridon</option>\n"
      stringin = stringin + "         <option value=\"Mannoroth\">Mannoroth</option>\n"
      stringin = stringin + "         <option value=\"Medivh\">Medivh</option>\n"
      stringin = stringin + "         <option value=\"Shattered Hand\">Shattered Hand</option>\n"
      stringin = stringin + "         <option value=\"Skullcrusher\">Skullcrusher</option>\n"
      stringin = stringin + "         <option value=\"Stormrage\">Stormrage</option>\n"
      stringin = stringin + "         <option value=\"Warsong\">Warsong</option>\n"
      stringin = stringin + "         <option value=\"Zul'jin\">Zul'jin</option>\n"
      stringin = stringin + "      </select>\n"         
      stringin = stringin + "   </div>\n"
      stringin = stringin + "   <div style=\"position: absolute;top: 165px;left: 314px;z-index: 1;\">\n"
      stringin = stringin + "      <img src=\"blank.png\" onclick=\"makeRequest('')\" />\n"
      stringin = stringin + "   </div>\n"
      stringin = stringin + "   <div style=\"position: absolute;top: 234px;left: 35px;z-index: 1;\">\n"
      stringin = stringin + "      <div style=\"padding: 0; width: 376px; height: 386px; overflow: hidden;\">\n"

      var stringout =    "   </div>\n"
      stringout = stringout + "</div>\n"
      stringout = stringout + "</body>\n"
      stringout = stringout + "</html>\n"

      document.write(stringin + string + stringout);
                 
            } else {
                alert('There was a problem with the request.');
            }
        }

    }
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Mon Sep 10, 2007 - 7:39 am    Post subject: First question Reply with quote

Without looking at the code: Did you set "AllowNetworkAccess" to true/yes in "Info.plist"?

And equally important:

Does the Console-Window show any error-messages when you start the widget?

(Guess, someone should write a faq about these things...)
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
hammo



Joined: 07 Sep 2007
Posts: 3

Posted: Mon Sep 10, 2007 - 9:44 am    Post subject: Reply with quote

AllowNetworkAccess was set to <true/> and the only two errors I receive in the JS Console are when you actually load the content in -- so the content does load in Safari, simply not in the Widget.
View user's profile Send private message Send e-mail Widgets
Greenie



Joined: 08 Jun 2005
Posts: 81

Posted: Mon Sep 10, 2007 - 9:54 am    Post subject: Reply with quote

hammo wrote:
AllowNetworkAccess was set to <true/> and the only two errors I receive in the JS Console are when you actually load the content in -- so the content does load in Safari, simply not in the Widget.


I guess there's a bit of a misunderstanding here. Actually I was not talking about the JS-Console within Safari but the Console-Application that is found in the utilities-folder on your hd. Because that's where error-messages/alerts appear if you start your widget within dashboard.

btw: it might be useful if you could provide a link to your widget so one can try it out and play around with it to find out what's going wrong.

Ah yes, and it seems as if your form-element isn't closed in the source, though I don't think that's the main problem here.
View user's profile Send private message Send e-mail AIM Address ICQ NumberWidgets
hammo



Joined: 07 Sep 2007
Posts: 3

Posted: Mon Sep 10, 2007 - 4:14 pm    Post subject: Reply with quote

Ah, ok -- there's an error in there about CFBundleVersion, but I don't see why as there is a string in the plist

Also, there is an error in the wowarmory.com/js/armory.js file that the page itself links to, however that is an actual error on their side as opposed to mine.

Does the widget ONLY work if everything is 100%?

hxxp://www.highervoltage.net/hana/WOW Armory.wdgt.zip -- Here's a link
^- set to http

Thanks for the help, as well! Smile
View user's profile Send private message Send e-mail Widgets
TheDrummer



Joined: 30 Oct 2007
Posts: 2
Location: Austria

Posted: Tue Oct 30, 2007 - 2:47 pm    Post subject: Reply with quote

well maybe you can help me here...!?
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