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 Contributor
jayant_biz4
Posts: 3
Registered: ‎09-06-2012
My Device: Blackberry Curve 9320

BB10 WebWorks Event Listeners not working

I am building an application which is essentially a wrapper over an external website. In the body onLoad event of index.html, i am creating event listeners to listen to application events and then loading the external website by using window.location.href = <new website>.

 

The website loads fine but after that none of the application event listeners are fired. I suspect it is because along with index.html the code containing the event listeners gets unloaded and hence event s are not firing. Is this correct? And if yes, what is the right way to implement this kind of functionality? I have declared all the necessary permissions in config.xml and the right access elements as well.

 

The code for index.html and the javascript is given below. Any help will be highly appreciated.

 

Thanks

Jayant

 

index.html

<html>
<head>
	....
        ....

	<script type="text/javascript">
	    function onLoad() {
		   document.addEventListener("webworksready",            loadExternalWebsite, false);
		}
	</script>
</head>
<body onLoad="onLoad()">
	
</body>
</html>

 

scripts.js

function loadExternalWebSite(){

	//add event listeners
	blackberry.event.addEventListener("pause", function (){
                    //window.alert("Application paused");
                    
                    try{
                        var appNotify = document.getElementById("Webapp_hf_AppNotify");
                        if (appNotify)
                            appNotify.value = 0;
                    }
                    catch(err){
                        //ignore
                        console.log('Error app notify');
                    }
                });

	 //add more event listeners

	//build website URL
        //this functions just appends some parameters to be passed to the  website to URL
	websiteUrl = buildURL();

        //load external website
	window.location.href = websiteUrl

}

 

Please use plain text.
BlackBerry Development Advisor (Retired)
erikjohnzon
Posts: 245
Registered: ‎09-21-2012
My Device: Q10

Re: BB10 WebWorks Event Listeners not working

By doing things this way you are essentially telling this system the following:

 

1. Load MY index.html where you include webworks.js (your hook into the actual API's)

2. Once webworks ready is fired load another page.

 

The problem is that this other page won't have the webworks.js file on it. So you can't get any API's and your event listeners are gone. So yes you are right this is what is happening.

 

You need to add the code in your index.html onto the ACTUAL website you are trying to load. The use case of wrapping someone elses website and then injecting your own code/webworks.js is not really supported, although it is possible.

 

Send me an email if you really injection is what you would like to do.

@erikjohnzon
erjohnson@blackberry.com
Please use plain text.