To main page | Opera Unite HowTo'sBasic HowTo: Simple app (tutorial)If you are looking for a way to monitor your visitors - any general web counter will do - try StatCounter → (just add code to the end of index.html of your service). TutorialHow to create a simple application that increments a single variable with Opera Unite and share it with the world:(Create any folder to hold the files) 1. Create config.xml file: <widget> <widgetname>Test</widgetname> <feature name="http://xmlns.opera.com/webserver"> <param name="type" value="service"/> <param name="servicepath" value="test"/> </feature> </widget>2. Create index.html file: <script> var counter = 0; window.onload = function () { webserver = opera.io.webserver if (webserver) { webserver.addEventListener('_index', start_page, false); // [1] } } function start_page(r) { counter++; var o = r.connection.response; o.write('This page has been seen <b>'+counter+' times</b>!!'); o.close(); } </script>// [1] is a remark -- there you can define additional pages, replacing "_index" with other values, which is final part of URL, i.e. webserver.addEventListener('other', another_page, false);will create a page http://yourcomp.yourid.operaunite.com/test/other, which will call function another_page(r). "test" is the name of app (defined in config.xml). By no means this is a complete example. You can expand it, you can replace <script> tag with <script src="script.js"></script> and put your script into scrpit.js and use HTML too. * Activate Opera Unite if it is not active (Opera will ask about that, if needed) 4. Drag and drop your config.xml into Opera. It will ask whether you want to install this. Confirm by pressing OK. You're done Updating app5. If you modify the index.html file - your page will still show old version. Right-click Opera Unite button, click "Manage Services" (or just press F4 to show/hide left sidebar), right click "Test" service, click "Stop Service", then click "Start Service" - this will reload the source files and reset your counter. Reset function might deal with it, but I'm not sure yet.To solve the resetting counter problem (if you stop the service or close Opera - all values are reset) - we need to add persistence to script. See also: Debugging Opera Unite apps Sharing app6. To share your Web Apss with others - copy your URL from address bar (F8 - Ctrl+C in Opera) and change it like so:unite:// -> http:// so, unite://my_compute.my_opera_login.operaunite.com/test/becomes http://my_compute.my_opera_login.operaunite.com/test/You can give this address away to your friends. 7. Use Markuper for HTML templating Problems1. Hiding Web App from dashboard while developing it?FurtherSee CRUD and static for more advanced example. | Last updated
|