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
Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

how to intercept the url in blackberry 10 webview

Hi,

 

I am working on HTML5WebWorks application.

 

I opened a WebView using : "window.open(https://myapp.com/xyz.html,"_self")".

 

I need to capture "urlChanged() signals".

 

Can I achieve it from javascript?

 

please guide me.

 

Thanks

Shwarup

Thanks,

Shwarup Biswas
BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: how to intercept the url in blackberry 10 webview

Hello,

 

There is no event for the url changing at this time.  What you may want to do is use a setInterval to check the url every so often.  I'll have some new OAuth samples going online in the next few days in our GitHub repo which do exactly that.

Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: how to intercept the url in blackberry 10 webview

Hi Chadtatro,

 

Thanks for your reply. setInterval is not working after opening  an url in webView using "window.open()"

 

But I need to capture changed url after openning a page in webview.

 

I used bellow code inside head tag as bellow:

 

<head>

   var _savedURL = "";

   function urlChanged() {  
    var currentURL = window.location.href;
    if(_savedURL !== currentURL){
     alert("_savedURL = "+_savedURL);
    }    
   }
   setInterval(urlChanged, 1000);
  </script>

 

</head>

 

How to fire this code after change an url in webView?

 

Thanks,

Shwarup Biswas
BlackBerry Development Advisor
Posts: 762
Registered: ‎10-01-2009
My Device: All
My Carrier: N/A

Re: how to intercept the url in blackberry 10 webview

you have to refer to the current open childwindow object to get the location and all that..

 

   var url = 'https://api.twitter.com/oauth/authorize?' + requestParams;
    childWindow = window.open(url, '_blank');

	// evaluate the url every second, when facebook redirects to our callback url, the following if statements gets fired
	window.int = self.setInterval(function(){
    var currentURL = childWindow.window.location.href;

    var callbackURL = twitterOptions.callbackUrl;
	var inCallback = currentURL.indexOf(callbackURL);

	  // location has changed to our callback url, parse the oauth code
	  if (inCallback == 0) {

		// stop the interval from checking for url changes	
		window.clearInterval(int)

		// parse the oauth codes
		var oauthToken = checkForQueryStrings('oauth_token') || null;
		var oauthVerifier = checkForQueryStrings('oauth_verifier') || null;

		// close the childWindow
		childWindow.close();
		
		setTimeout(function(){ getOAuthToken(oauthToken, oauthVerifier); }, 1000);
	 }

 

Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: how to intercept the url in blackberry 10 webview

Hi Chadtatro,

 

Thanks for your quick reply.

 

 "setInterver()" method is not working in my environment.

Device gets power off when control comes to

"setTimeout(function(){ getOAuthToken(oauthToken, oauthVerifier); }, 1000);" this code.

 

What is the reason for this?

 

 

Thanks,

Shwarup Biswas
Highlighted
Developer
Posts: 93
Registered: ‎08-18-2011
My Device: 9550
My Carrier: At&T

Re: how to intercept the url in blackberry 10 webview

Still this setInterval() method is not working after open the page in webview.

 

My use case is: I need to check if url is changed in the webview after login page is loaded.

 

Just verifying my application flow:

 

1. I established http connection and got a whole html page as response.

2. Used window.open() as bellow:

    childWindow = window.open("data&colon;text/html,"+unescape( encodeURIComponent( xmlhttp.responseText ) ),"_self");

    to open the page in webview.

3. setInterval() after open page in webview as bellow:

window.int = self.setInterval(function(){
   var currentURL = childWindow.window.location.href;

   var callbackURL = "";
   var inCallback = currentURL.indexOf(callbackURL);

     // location has changed to our callback url, parse the oauth code
     if (inCallback == 0) {

    // stop the interval from checking for url changes 
    window.clearInterval(int)

    // close the childWindow
    childWindow.close();
    setTimeout(function(){getOAuthToken(); }, 1000);
   } }); 

 

I need some help to over come it pls.

 

 

 

Thanks,

Shwarup Biswas