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

Native Development

Reply
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Reading web content fetched by Webview

hello there,

 

how do I read web content fetched by a WebView.  The content loads fine within the Webview but I'm unable to read it or more imporatantly in my case determine if the content retreived is empty, which is what I would like to know.  Accordingly the html is blank as per the documentation because it was never set using setHtml().

 

thanks



GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 265
Registered: ‎01-02-2011
My Device: Z30, PlayBook
My Carrier: AT&T

Re: Reading web content fetched by Webview

Did you try looking at the HTML property of the WebView?

i.e.  myWebView.html.

 

var returnHTMLlen = webWindow.html.length();

 

 

What action are using to determine if the WebView changed?

 

For example, when I send an authenication request, I check the OnURLChanged to determine if the next step of the authentication has happened.

_________________
Meetup for BlackBerry 10
Meetup Search Tool - not available at the moment
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Re: Reading web content fetched by Webview

Hi,

My webview is calling the same URL, sometimes the server will return a code fragment other times it will return nothing, if there was a way to look at the hrml being returned it would be html.length== 0. But there is no way for me to find out when html.length == 0


GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 1,028
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Reading web content fetched by Webview

Have you considered injecting JavaScript with evaluateJavaScript() to test the actual DOM and then return a value using postMessage()?


Robdob wrote:

hello there,

 

how do I read web content fetched by a WebView.  The content loads fine within the Webview but I'm unable to read it or more imporatantly in my case determine if the content retreived is empty, which is what I would like to know.  Accordingly the html is blank as per the documentation because it was never set using setHtml().

 

thanks






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Re: Reading web content fetched by Webview

Hi, could you please post some sample qml code as to how I could do this.

Thanks


GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reading web content fetched by Webview

[ Edited ]

It wouldn't be QML you are writing you would need to write a javascript script and pass it to the evaluateJavaScript() function...

 

http://developer.blackberry.com/native/reference/cascades/bb__cascades__webpage.html#function-evalua...

 

http://javascript.info/tutorial/searching-elements-dom


If you've been helped click on Like Button, if you've been saved buy the app. :smileyhappy:

Developer of stokLocker, Sympatico and Super Sentences.
Developer
Posts: 1,028
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Reading web content fetched by Webview

Good links. Thanks for following up for the OP regarding my suggestion. I''ve been a little distracted since Wednesday since I got a new Dell 16GB i7 touchscreen laptop and I've been setting it up, which usually takes me days until I'm satisfied. It's taking even longer this time since the first two were defective out of the box and I'm on the third one now, which seems to be fine.


BBSJdev wrote:

It wouldn't be QML you are writing you would need to write a javascript script and pass it to the evaluateJavaScript() function...

 

http://developer.blackberry.com/native/reference/cascades/bb__cascades__webpage.html#function-evalua...

 

http://javascript.info/tutorial/searching-elements-dom






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.
Developer
Posts: 244
Registered: ‎01-31-2013
My Device: Developer

Re: Reading web content fetched by Webview

I understand you don't write it in qml, what I mean't was that I was trying to test for an empty page from within my qml OnLoadingChanged().  Is there not an easier way to tell if the page being returned is empty, i.e. length == 0?  or is there an example of doing exactly what I'm trying to do already posted somewhere..  the page is for banners, so I guess if the page doesn't contain an <a href then for my purpose I can consider it something to be considered empty..

 

Thanks.



GeoYeo - Free Local classifieds - Built for Blackberry 10, if you like it please Rate It and Share it!
Developer
Posts: 1,028
Registered: ‎03-20-2013
My Device: Red LE Developer Z10
My Carrier: Fido

Re: Reading web content fetched by Webview

[ Edited ]

Basically, yes. Search for an element you expect to be there in a valid page. If you don't know what the loaded page will contain, just look for a "body" element. You should be able to get a return value from evaluateJavaScript() via token, but if not you will need to use postMessage() to send a found/notfound message back to your QML.

 

There really isn't a QML only way to do this since the HTML property of a WebView isn't updated when the URL is set or a user navigates.


Robdob wrote:

I understand you don't write it in qml, what I mean't was that I was trying to test for an empty page from within my qml OnLoadingChanged().  Is there not an easier way to tell if the page being returned is empty, i.e. length == 0?  or is there an example of doing exactly what I'm trying to do already posted somewhere..  the page is for banners, so I guess if the page doesn't contain an <a href then for my purpose I can consider it something to be considered empty..

 

Thanks.






Developer of Built for BlackBerry certified multiFEED RSS/Atom feed reader and aggregator.  multiFEED Icon

Play nice: Clicking Like Button on posts that helped you not only encourages others to continue sharing their experience, but also improves your own rating on this board. Also, don't forget to accept a post if it solves your problem or answers your question.