×

Discussion Board

Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    WTR Widget right for my application?

    WTR Widget is a new concept for me and despite reading up on it Im not getting it completely. Thats why I would like to ask you if my application is suitable as a WTR Widget.

    My application consists of a set of html-documents. Each document includes css and some javascript. As for media, they play sounds (mp3) and display images (png and jpg).

    I would like to add it all in one package, and distribute it via Ovi-store for a fee.

    Is WTR Widget the way to go for me, or is it not possible to have the Widget load all its content locally rather than from a remote webserver?

  2. #2
    Registered User
    Join Date
    Feb 2009
    Posts
    52

    Re: WTR Widget right for my application?

    yes you can accomplish that using WRT, and make your application offline.
    You can have multiple html files that can be linked from a main page, like how you would design a basic website.

  3. #3
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    Re: WTR Widget right for my application?

    That sounds great. WRT certainly seems like the right choice for me then.

    I understand that css is supported, but how about WebKit?

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    52

    Re: WTR Widget right for my application?

    don't quite understand that question. the s60 browser which WRT is running on, is based on webkit.

  5. #5
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Akron Ohio USA
    Posts
    229

    Re: WTR Widget right for my application?

    One thing to be aware of is that if you navigate from the html document specified in the config file to another html document, the WRT environment will close the javascript widget api. The widget api is only available for html document defined in the config file.

    To make your "web site" idiomatic for WRT environment, you should consider building it as a javascript application instead, so that all assets load via javascript into the application, not as a collection of distinct html documents. This will enable you to keep the widget api.

    The means to do this will depend upon the requirements of your application. A simple thing to do is to use xml request to load a html fragment stored as a seperate document within the WRT archive and insert this into a div tag of your start HTML document, using innnerHTML Javascript property.

    You can dynamically embed sounds using Javascript, though you might find that the user experience is better if you use window.location.href to load the sound and allow the browser to pass the sound to the phone sound player.

  6. #6
    Nokia Developer Moderator
    Join Date
    Jun 2007
    Posts
    219

    Re: WTR Widget right for my application?

    Quote Originally Posted by Danneman View Post
    That sounds great. WRT certainly seems like the right choice for me then.

    I understand that css is supported, but how about WebKit?
    hi, feel free to send me a note at ung-ping.tian@nokia.com if you need further help to publish the widget to Ovi (http://publish.ovi.com). Hope to see your widget there when the store opens...

    also, do consider to upload your widgets to Calling All Innovators contest as well, http://www.callingallinnovators.com/...nnovation.aspx, to win cash prizes, premium placement at Ovi Store and etc...

    All the best!

  7. #7
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    Re: WTR Widget right for my application?

    InYourDreams:
    You certainly did answer my question - thanks a lot


    uptian:
    Its nice to see that you can get help from the developers/nokia staff. That was certainly not the case when developing for iPhone. Thanks


    hp3:
    But what are the downsides of going from the widget to the browser, besides the transition between programs which will make it seem less smooth to the user? I will still have access to the local content (all other html-files, sounds and images), and the project will still be css-, javascript- and webkit-enabled, right?

    It would certainly be favourable to use the "innerHTML"-method you are describing, but seeing as I have a lot of html-pages ready to use it seems that it would require a LOT of editing.

    Before investigating this option furter, what can you tell me about these alternatives? Are they possible?

    1) Can you define more than one html-file in the config.file?

    2) Is it possible to use "innerHTML" to open a specific html-file, extract a portion of its html-code (for instance, the code inside a uniquely named div-tag), and insert it into the main-html (the one defined in config)?


    Acutally, when thinking about it some more it seems the innerHTML + XML option you present wouldnt require that much work. Am I right in assuming that this is the work involved:

    1) Create an xml-file with one tag for each html-file, and naming that tag after the html-filename.

    2) Insert the code AS A STRING inside the body-tags of each html-file in its corresponding tag in the xml-file.
    Question: How do you maintain the html-code as a string inside an xml-tag when the html-code contains tags and ""-signs of its own?

    3) Create the main-html defined in the config, with a div-tag just between the body-tags which uses the innerHTML-method to call the appropriate tag inside the xml-file - thus loading a html-file. The name of the tag should be a variable saved between sessions.
    Question: Does WRT widgets support cookies? Otherwise how can I save the variable between sessions so that the last open html-page is the one loaded the next time the user opens the program?

    4) Create a javascript-function that parses the xml-file.
    Question: Any suggestions to where I can read up on a xml-parser that will work with WRT widgets?

  8. #8
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Akron Ohio USA
    Posts
    229

    Re: WTR Widget right for my application?

    only one HTML file in config.

    Its been my experience hat when you navigate from the starting HTML file to another HTML file the WRT environment shuts down certain apis, like the menu, which may be problematic for your application. You might try this out to see how it affects your project. Perhaps it does not affect it at all.

    To get the effect of loading html files in a Javascript application, you could try the following. Manually copy the essential html within the each of your HTML files and paste into a new file and save it as a html fragment text file. The extension may not even matter, perhaps just try .txt. So, you just have html without the head and body structural tags. Do this for each HTML file.

    Then using Javascript in your WRT starting HTML page, you will load a given .txt file through the xhmlHTTPRequest object as plain text not xml. There is no need to parse it as xml. Just pass the string from the xhr object to your div innerHTML. The browser will display the HTML. This will keep your existing HTML content intact and enable you to load as much content as you want while maintaining the WRT environment.

    You could also use an iframe but that might have more awkward navigation issues than dynamically loading the html fragment into the actual page. I am not sure if the document in the iframe has access to the WRT proprietary apis.

  9. #9
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    Re: WTR Widget right for my application?

    hp3: The seems like a very god idea!

    I tried making a sample-code that would work in that way, but cant get it to work. When pressing one of the menu-buttons, nothing happens:

    Code:
    // -------------------
    // myJavaScriptCode.js
    // -------------------
    
    // Parameter with the name of the file to open
    function GetHTMLContent(htmlFileName)
    {
    	// 1. GET CONTENT FROM FILE
    	// ------------------------
    	
    	// Create a XMLHttpRequest-object
    	var htmlFileContent = new XMLHttpRequest();
    
    	// Open the file
    	htmlFileContent.open('GET', htmlFileName);
    
    	// Store the content in the file in the XMLHttpRequest-object (correct format?)
    	htmlFileContent.send();
    
    	
    
    	// 2. REPLACE DIV-TAG WITH CONTENT
    	// -------------------------------
    	
    	// Replaces the "replacecontent"-tag with the content in the XMLHttpRequest-object
    	// Q: Is "htmlFileContent" the correct format?
    	document.getElementById('replacecontent').innerHTML = htmlFileContent;
    
    }
    
    
    
    
    
    
    
    
    
    // -------------------
    // main.html
    // -------------------
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
            <title>Hello World</title>
            <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
            <link rel="stylesheet" type="text/css" href="myStyleSheet.css" />
            <script type="text/javascript" src="myJavaScriptCode.js"></script>
    </head>
    
    <body id="body">
            <div id="replacecontent">
    	
    		<!-- A SIMPLE MENU -->
    
    		<input type="button" value="Go to file01" onClick="GetHTMLContent('file01.txt');">
    
    		<input type="button" value="Go to file02" onClick="GetHTMLContent('file02.txt');">
    
    		<!-- etc... -->
    
            </div>
    </body>
    </html>
    
    
    
    
    
    // -----------------
    // file01.txt
    // -----------------
    
    <h1>File 1</h1>
    
    
    
    
    
    // -----------------
    // file02.txt
    // -----------------
    
    <h1>File 2</h1>

  10. #10
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: WTR Widget right for my application?

    maybe you should check how the HTTP request can be used from the Wiki examples: http://wiki.forum.nokia.com/index.ph...th_WRT_widgets

  11. #11
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    Re: WTR Widget right for my application?

    Any example in particular that you know uses http request? There are quite a few

  12. #12
    Nokia Developer Expert
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,142

    Re: WTR Widget right for my application?

    if you leave google & yahoo's out, rest of them should be using HTTP request normally.

  13. #13
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Akron Ohio USA
    Posts
    229

    Re: WTR Widget right for my application?

    you are missing a few things. The responseText property of the xhr object contains the HTML fragment, and you must wait until the file loads using the onreadystatechange callback before you can do anyting with the responseText.

    You might review this tutorial as an example.

    http://swik.net/Ajax/How+to+use+XMLHttpRequest

    Also it is good to start testing in Firefox because the javascript error consol gives better indication of problems than the SDK emulators or the phone. You might also check out the Nokia WRT plug-in for Aptana studio which streamlines the process of testing, packaging and deploying.

  14. #14
    Regular Contributor
    Join Date
    Apr 2009
    Posts
    54

    Re: WTR Widget right for my application?

    Since Im trying to deduce the functionality mainly by code-samples, its proving a bit difficult

    Ive updated the .js-file to take into account the onreadystatechange (correct syntax?) and that it is the responseText-property that returns the text in string-format.

    Code:
    function GetHTMLContent(htmlFileName){
    
    	var htmlFileContent = new XMLHttpRequest();
    	
    	htmlFileContent.open("GET", htmlFileName, true);
    	
    	htmlFileContent.onreadystatechange = function(){
    		if (htmlFileContent.readyState == 4) {
    			document.getElementById('replacecontent').innerHTML = htmlFileContent.responseText;	
    		}
    	}
    	
    	htmlFileContent.send(null);
    }
    Still no response at all, despite testing it on both ie and firefox. Is it a syntax-issue that can be easily spotted by more trained eyes, or have I missed something more essential?


    UPDATE:
    When replacing the local file-name ("file01.txt") with a textfile on a server, this works just fine. But only in IE! It does not work in Firefox or in Opera.

    First issue: The file01.txt is placed in the same folder as all the other files. Simply referring to it by its name in the second parameter of the xhr.open()-function should be enough, shouldnt it?

    Second issue: Ive tried using a code that will differentiate between browsers:

    Code:
    function getHTTPObject() {
        if (typeof XMLHttpRequest != 'undefined') {
            return new XMLHttpRequest();
        }
        try {
            return new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                return new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
        return false;
    }
    
    function GetHTMLContent(htmlFileName){
    
    	var htmlFileContent = getHTTPObject();
    	
    	// Can't access local file, only remote.
    	htmlFileContent.open("GET", "http://myserver.com/file01.txt", true);
    	
    	htmlFileContent.onreadystatechange = function(){
    		if (htmlFileContent.readyState == 4) {
    			document.getElementById('replacecontent').innerHTML = htmlFileContent.responseText;	
    		}
    	}
    	
    	htmlFileContent.send(null);
    }
    This seems to do nothing for the usability of other browsers, and IE continues to be the only browser that works with this code.
    Last edited by Danneman; 2009-04-14 at 20:25.

  15. #15
    Regular Contributor
    Join Date
    Apr 2003
    Location
    Akron Ohio USA
    Posts
    229

    Re: WTR Widget right for my application?

    I would do the following:

    make htmlFileContent a "global" variable incase the scope of a local variable is causing a problem with the onreadystate change callback.

    var htmlFileContent = new XMLHttpRequest();
    function GetHTMLContent(htmlFileName){
    // remove the line var htmlFileContent = new XMLHttpRequest();
    ...
    }

    Put an alert statement in the callback to see if it is executing at all.

    alert(htmlFileContent.readyState)

    You might also try loading with a different file extension like .html, or .xml

    Sometimes it is better to work with a simple script on its own, to isolate a problem, instead of in the context of a larger application.

Page 1 of 2 12 LastLast

Similar Threads

  1. AutoStart My application at bootup
    By prakashs in forum Symbian C++
    Replies: 7
    Last Post: 2009-03-24, 10:06
  2. Replies: 37
    Last Post: 2008-07-16, 05:17
  3. Replies: 4
    Last Post: 2008-07-15, 11:37
  4. Replies: 1
    Last Post: 2008-05-08, 12:32
  5. Replies: 0
    Last Post: 2005-05-28, 10:20

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •