0

When Im opening a page in the childbrowser on page1 I want to run a function when I close it, and it works. But when I go to page2 and open another page in the childbrowser it runs the function here as well and I dont want that.

So how can I run a function when I close the childbrowser on just page1 and not on page2?

Im using this on page1 to run the function when Im closing the CB.

   var apptypen='iPhone';

$(document).ready(function(){

    if (apptypen=='iPhone'){
        alert("apptype iphone");

    window.plugins.childBrowser.onClose=function(){

    jQT.goBack(1);
    window.plugins.childBrowser.onClose = null;
        }
    }
    });

When I opens the CB on page1 it runs the alert and it goes back with the jQT.goBack(1); function, but if I open the CB on page2 it doesent run the alert, but it does run the jQT.goBack, and thats what I dont want. It should only run jQT.goBack when I open the CB on page1 and not when I open a page in the CB on page2. Any input appreciated, thanks. Solved, I had to have window.plugins.childBrowser.onClose = null; after the jQT.goBack.

Claes Gustavsson
  • 5,509
  • 11
  • 50
  • 86

1 Answers1

0

You'll want to register a location change listener. Then when you move to page 2 you can set a global variable or remove the close listener. Your choice.

window.plugins.childBrowser.onLocationChange = function(loc) {
    if (loc == "page1.html") {
        window.plugins.childBrowser.onClose = function() {
           alert("close");
        };
    } else if (loc == "page2.html") {
        window.plugins.childBrowser.onClose = null;
    }
};
Simon MacDonald
  • 23,253
  • 5
  • 58
  • 74
  • Hi Simon, long time. Ok, but if I want to not run a function on any other pages that uses the CB, what would that look like? else if(loc == "*") or something? Thanks. – Claes Gustavsson Feb 08 '13 at 14:44
  • else if (loc != "page1.html") for instance. – Simon MacDonald Feb 08 '13 at 15:57
  • locationchange is the location in the CB, right? So if the location in the CB changes then run a function? If so, then I need to clarify, I don't want it to change depending on the page that Im opening IN the CB, I want it to run a function if I open the CB ON page1 and not if I open the CB ON page2. :-) – Claes Gustavsson Feb 08 '13 at 16:35
  • Then all you need to do is to remove your onClose handler before you open page2. – Simon MacDonald Feb 09 '13 at 04:29
  • Ok, thanks. Now I understand how it works :-) All I had to do was to set window.plugins.childBrowser.onClose = null; after jQT.goBack(1); Thanks a lot Simon. – Claes Gustavsson Feb 09 '13 at 08:29