1
votes

I am currently building an application on Windows Phone 7 using the WebBrowser control. The WebBrowser is navigated to a URL, but I also inject my own javascript into the control.

However the code which seems to work well on other platforms (WebView for Android and iOS) doesn't seem to work in the WebBrowser:

function parseToString(outObject)
{
    var outJSON = null;
    try{
        if(outObject != null){
            outJSON = JSON.stringify(outObject);
        }
    }
    catch(err)
    {
        outJSON = err.message;
    }
    window.external.Notify(outJSON);
}

I found out that the "control JSON is undefined" is thrown in the try block.

Can someone recommend an alternative method for stringifying the JSON in the WebBrowser/IE? Furthermore, I cannot use external libraries as those javascripts are injected into the WebBrowser.

2

2 Answers

1
votes

The WP7 browser does not supply a JSON object, so you will need to use a third party library in order to convert an object into a JSON string. I have used both of these in the past:

See this related question:

Serializing to JSON in jQuery

0
votes

I had the same problem, but then added the following to the top of the HTML document:

<!DOCTYPE html>

This unfortunately doesn't help if you don't have access to the HTML document and are only injecting JavaScript, but someone might find it useful.