Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
New Developer
Posts: 5
Registered: ‎09-11-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

I am having trouble persisting and retrieving cookies when using the browser.field.

If I set a cookie, and then try to read that cookie, the read inevitably returns nothing.

Is the container of the browser.field supposed to implement the getting and setting of the cookies? If so, it is clear that the container can catch the EVENT_SET_HTTP_COOKIE event, and maintain state. What is not clear is how the container can catch the javascript request to get a cookie, as there is no EVENT_GET_HTTP_COOKIE event in the documentation (http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/browser/field/Event.html).

(BTW, I have not seen EVENT_EXECUTING_SCRIPT fire, even though my application is executing javascript.)

My test app performs the following actions:

 

1. open an alert dialog to indicate start
2. create a timer and look for a changed value in a cookie
3. open another alert dialog to indicate end
4. set the cookie to a value
5. the timer code notices the changed cookie and sends an alert indicating that the cookie changed value

This test case works as expected using both desktop browsers and the blackberry browser. However, it fails in the blackberry browser.field, because, as mentioned, the cookie does not change value.

So, I am currently blocked from using the browser.field. I cannot make AJAX (XMLHttpRequest) calls, and I cannot persist cookies.


Below are my javascript wrapper methods for getting and setting cookies.

// -----------------------------
// Basic Cookie Methods
// -----------------------------
function setCookie(c_name,value,expiredays)
{
    createCookie(c_name, value, expiredays);
}
function createCookie(name,value,days)
{
    if (days)
    {
        var date = new Date();
        date.setTime(date.getTime()+ (days*24*60*60*1000));
        var expires = ";expires=" + date.toGMTString();
    } else var expires = "";
    document.cookie = name + "=" + value + expires + ";path=/";
}
function eraseCookie(name)
{
    createCookie(name, "", -1);
}

function getCookie(c_name)
{
    if (document.cookie.length>0)
      {
      c_start=document.cookie.indexOf(c_name + "=");
      if (c_start!=-1)
        {
        c_start=c_start + c_name.length+1;
        c_end=document.cookie.indexOf(";",c_start);
        if (c_end==-1) c_end=document.cookie.length;
        return unescape(document.cookie.substring(c_start,c_end));
        }
      }
    return "";
}

BlackBerry Development Advisor
Posts: 14,950
Registered: ‎07-09-2008
My Device: BlackBerry Passport

Re: Blackberry browser support for AJAX

The browser field does not currently support AJAX. 

 

The following link explains how to implement cookie support in the browser field.

 

How To – Enable cookies in BrowserField 
Article Number: DB-00675

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800440/How_To_...

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Retired
Posts: 18
Registered: ‎07-14-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

Hello,

 

Please have a look at this KB article - How to enable cookies in BrowserField.

 

-Jeremy

Jeremy Weber
Sr Application Development Consultant
Research In Motion
New Developer
Posts: 5
Registered: ‎09-11-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

Jeremy and Mark,

 

Thank you for the quick response. I have a few more questions as a follow-up:

 

1. Is the javascript method "eval()" supported in browser.field?

 

My quick tests indicate that this is NOT suported in browser.field. Of course, the only reason to use XMLHttpRequest would be to eval the returned javascript/json within the page. So, is it true that both of these javascript methods (XMLHttpRequest and eval()) are not supported in browser.field?

 

2. Is the javascript method "document.write()" supported in browser.field?

 

Again, my quick tests indicate that this is NOT supported in browser.field.

 

3. Does the browser.field container have access to the DOM within the browser.field, and can the container manipulate that DOM?

 

I have NOT seen any DOM-like api's in the browser.field package docs.( http://www.blackberry.com/developers/docs/4.6.0api/net/rim/device/api/browser/field/package-summary.... ) However, I can only hope that I've overlooked something. 

 

4. Is there any documentation regarding the differences in browser.field and browser? 

 

Specifically, it would be nice to know what javascript API's are supported in each.

 

5. Is there any other browser.field-like class(es) that I should be looking at? I am clearly attempting to build a robust application with an embedded browser that is using standard AJAX (xmlhttprequest and eval() methods. My tests indicate that the BB web browser supports everything I need, but it's not embeddable (to my knowledge).

 

So...what are my options here? 

 

-Todd

New Developer
Posts: 5
Registered: ‎09-11-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

Jeremy and Mark,

 

Further clarification:

 

1. net.rim.device.api.browser.field DOES support javascript.eval(), and this eval works with function definitions, JSON, and function invocation.
 
2. document.write() IS supported, at least at the time of page load. However, see #3 below.
 
3. Outside of page load, neither document.write() nor innerHTML are producing any rendered changes in the net.rim.device.api.browser.field. However, at the end of page loading, or thereabouts, the net.rim.device.api.browser DOES render the results of these DOM changes. So, somehow net.rim.device.api.browser notices changes to the DOM and refreshes the page, whereas the browser.field impl doesn't have this check. 
 
4. My suspicion is that net.rim.device.api.browser set's a dirty flag and invokes a repaint at some point after the js has finished executing (or the page has finished loading). You can see this in the net.rim.device.api.browser like so:

(See code snippet below for context)
 
function welcome()
{
        document.getElementById('h1text').innerHTML="WELCOME!";
        document.getElementById('h2text').innerHTML="WELCOME!";
}
function goodbye()
{
        document.getElementById('h2text').innerHTML="GOODBYE!";
}
 
This will result in a final rendering of:
 
WELCOME!
GOODBYE!
 
And this is what we'd expect, although we'd expect to see the intermediate stages rendered, too:
 
WELCOME!
WELCOME!
 
And then:
 
WELCOME!
GOODBYE!
 
 
So, the net.rim.device.api.browser is responding to the innerHTML and document.write() calls, but we're only seeing rendering at the end.

 

How could I get similar functionality with net.rim.device.api.browser.field?

 

-Todd

 


CODE SNIPPET:

 


<script type="text/javascript">
function foo()
{
    alert("spacer...");

    welcome();

    alert("spacer...");

    goodbye();
   
    alert("spacer...");
}
function welcome()
{
    document.getElementById('h1text').innerHTML="WELCOME!";
    document.getElementById('h2text').innerHTML="WELCOME!";
}
function goodbye()
{
    document.getElementById('h2text').innerHTML="GOODBYE!";
}
function reset()
{
    document.write("<html><head></head><body>body has been reset</body></html>");
}
</script>
</head>
<body onLoad="foo();">
    BODY

<h2 id="h1text" >...h1 text...</h2>
<h2 id="h2text" >...h2 text...</h2>
<script type="text/javascript">
document.write("Testing document.write() from within a script tag in the body...")
</script>
</body>
</html>

New Developer
Posts: 43
Registered: ‎07-29-2008
My Device: Not Specified

TGreenwood, have you already recognized that you are in the wrong forum with your browser.field?

This is the forum regarding content and web developement for the BlackBerry Browser and this is a thread about client-side Ajax.
New Developer
Posts: 19
Registered: ‎10-08-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

I have downloaded the 4.7 JDE and it DOES NOT include 9000 simulator, only 9500 and 9530.  Where can I get a 9000 simulator?  I have checked the normal simulator download page and it is not there either. 

 

Using the 9500 and 9530 simulators in the 4.7 JDE I tried to run javascript pages that previously didn't work.  Those pages still did not work in the new browser.  I made sure to "enable javascript" in the browser options also.  These pages were created with the latest version Google Web Toolkit (GWT) and run fine in Internet Explorer 7.0 and Firefox.

 

So I wondering if the new BB browser really does "fully support" java 1.5 as stated earlier in this thread.

Developer
Posts: 250
Registered: ‎07-18-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX


kknuth wrote:

I have downloaded the 4.7 JDE and it DOES NOT include 9000 simulator, only 9500 and 9530.  Where can I get a 9000 simulator?  I have checked the normal simulator download page and it is not there either. 

 

Using the 9500 and 9530 simulators in the 4.7 JDE I tried to run javascript pages that previously didn't work.  Those pages still did not work in the new browser.  I made sure to "enable javascript" in the browser options also.  These pages were created with the latest version Google Web Toolkit (GWT) and run fine in Internet Explorer 7.0 and Firefox.

 

So I wondering if the new BB browser really does "fully support" java 1.5 as stated earlier in this thread.


The 9000 simulator is included in the 4.6 JDE.

New Developer
Posts: 19
Registered: ‎10-08-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

Thanks!  Yes, JDE 4.6 does have the Bold 9000 simulator.

 

However, the results are the same.  Neither the 9000, 9500, or 9530 simulators run GWT apps.  So it would seem that Blackberry has some work to do to fully support AJAX and Javascript.

 

 

New Developer
Posts: 19
Registered: ‎10-08-2008
My Device: Not Specified

Re: Blackberry browser support for AJAX

BTW..

A good web page to test full GWT/ajax/javascript compatibility is here:

 

http://gwt.google.com/samples/Showcase/Showcase.html

 

Try to render those examples on a Blackberry. :smileysad: