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
Contributor
Posts: 20
Registered: ‎12-24-2010
My Device: 8520
Accepted Solution

how to exit the widget from a remote php file

 I want to exit the widget froma remote php file, I use the  onExit  

function trapForApplicationExit()
  {
      blackberry.app.event.onExit(handleExit);
  }


  function handleExit()
  {
         var answer = confirm("Leave this application?");
         if (answer)
           blackberry.app.exit();
  }

 

 

which needs to add  the feature blackberry.app.event to my config.xml file, the question is how can I add this feature to the remote files on the server?

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: how to exit the widget from a remote php file

Hi ahmed300,

 

Are you asking how can you setup your config.xml file so that it can access your remote page and also allow for this code to be run?

 

Or how can you detect the WebWorks application from your remote page and insert your JavaScript code?

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 20
Registered: ‎12-24-2010
My Device: 8520

Re: how to exit the widget from a remote php file

when i put  the onExit  function in an html page inside the widget(local)  and enters this page by the back button it works, but when i put the function in a php file on the server it doesn't work, I want the user to exit the widget when he press the back botton while he is viewing this php file on the server.

<html>
    <head>
      
<script type="text/javascript">
function getUrlVars() {  

 var vars = {};  

var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {  

 vars[key] = value;  

 });  

 return vars;  
   }
  function trapForApplicationExit()
  {
      blackberry.app.event.onExit(handleExit);
  }


  function handleExit()
  {
         var answer = confirm("Leave this application?");
         if (answer)
           blackberry.app.exit();
  }

</script>

    </head>




    <body onload='trapForApplicationExit()'>
<script type="text/javascript">
var first = getUrlVars()["flag"];
if(first!="ok"){document.write("<?php
 
if(isset($_COOKIE['usercode'])){
$usercode=$_COOKIE['usercode'];
$username=$_COOKIE['username'];

echo '<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL=local:///index.html \">';
}
else{echo '<META HTTP-EQUIV=\"Refresh\" Content=\"0; URL=login.php \">'; }?>");
}// Here under this condition I want the application to exit
if(first=="ok"){trapForApplicationExit();

}

        </script>





        </body>
</html>

 

Contributor
Posts: 20
Registered: ‎12-24-2010
My Device: 8520

Re: how to exit the widget from a remote php file

Hi tneil,

yes I'm asking how can I setup the config.xml file so that it can access the remote page and also allow for this code to be run?

 

Retired
Posts: 3,708
Registered: ‎10-16-2008
My Device: Z10
My Carrier: Rogers

Re: how to exit the widget from a remote php file

In your config.xml file where you have whitelisted your external domain, you will also want to add the feature element as a nested element. 

 

For example:

 

 

<access uri="http://www.mydomain.com" subdomains="true">
  <feature id="blackberry.app.event" />
</access>

 

This will allow the API to run in the external domain.

 

Tim Neil
Director, Application Platform & Tools Product Management
Follow me on Twitter
Contributor
Posts: 20
Registered: ‎12-24-2010
My Device: 8520

Re: how to exit the widget from a remote php file

[ Edited ]

hi tneil,

 

   

When I test, it gives me this error: 

TypeError: undefined is not a function.

Running at line 11: blackberry.app.exit();}.

Contributor
Posts: 20
Registered: ‎12-24-2010
My Device: 8520

Re: how to exit the widget from a remote php file

My problem is solved,

by adding this to my config.xml

 

 

<access uri="http://www.mydomain.com" subdomains="true">
  <feature id="blackberry.app.event" />

<feature id="blackberry.app" />

</access>