Blackberry BrowserField Issue -
Asked Answered
T

1

6

I am using 'net.rim.device.api.browser.field2.BrowserField' for loading an html page with 2 scripts.

  1. script 1 (Jquery)
  2. script 2 (Jquery mobile)

The 2nd script gets loaded twice. Its like the script gets loaded no. of times as per its position in the html file.

eg : 5th position script file will get loaded 5 times and respectively.

Thanks in advance.

Threedecker answered 14/3, 2012 at 12:52 Comment(3)
We have seen this same behavior in loading up to 5 script files, the 5th one being requested and loaded 5 times.Araby
are the scripts both separate .js files, referenced from the html page (not embedded <script> elements)?Tonality
Oh God, I remember this, it was absolutely horrible. Worse, I can't remember how to fix it offhand.Evilminded
T
0

I've been trying to reproduce, and am failing. Consider this simple BB app:

package mypackage;

import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;

public class MyApp extends UiApplication
{
    final class MyScreen extends MainScreen
    {
        protected BrowserField browser;
        protected static final String URL = "http://www.craigmj.com/bbtest/index.html";

        public MyScreen()
        {        
            setTitle(URL);          
            browser = new BrowserField();
            add(browser);
            browser.requestContent(URL);
        }
    }

    public static void main(String[] args)
    {
        MyApp theApp = new MyApp();       
        theApp.enterEventDispatcher();
    }

    public MyApp()
    {        
        pushScreen(new MyScreen());
    }    
}

Now the index.html it loads looks like this:

<html>
<head>
    <script language="javascript" src="js1.js"></script>
    <script language="javascript" src="js2.js"></script>
    <script language="javascript" src="js2.js"></script>
    <script language="javascript" src="js3.js"></script>
    <script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script language="javascript">
function loadFn() {
    res = "";
    for (var i=1; i<4; i++) {
        res += "js" + i + " = " + getCount("js"+i) + ", ";
    }
    document.getElementById("val").value = res;
}
    </script>
</head>
<body onLoad="loadFn();"><h1>Loading...</h1>
    <input type="text" id="val" name="val" size="30"/>
</body></html>

js1.js is:

function jsCount(jsFile) {
    if ("undefined"==typeof window[jsFile]) {
        window[jsFile] = 0;
    }
    window[jsFile] = window[jsFile] + 1;
}

function getCount(jsFile) {
    return window[jsFile];
}

jsCount("js1");

And js2.js and js3.js are:

jsCount("js2");

and

jsCount("js3");

(You can find them at http://www.craigmj.com/bbtest/...)

And I'm getting the results I expect on the 9700 simulator, and on my 9900 device.

js1 = 1, js2 = 2, js3 = 1,

It doesn't work on the Blackberry 5 OS, but that appears to be because the browser on BB5 doesn't support script tags.

Can we get some clarity on exactly where and how this error can be reproduced?

Twelvemonth answered 26/6, 2012 at 12:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.