call function from iframe to parent window

1,172 views
Skip to first unread message

Manuel Kaltenbach

unread,
Jul 6, 2012, 7:05:04 AM7/6/12
to phon...@googlegroups.com
Hello Community,

first, sorry for my bad englisch...

Now to the problem:

i have a index.html like this:

<body>
      <head>
            <script src="jquery.js"></script>
            <script>
                  $(document).ready(function(e) {
       myPublicFunction = function(){
alert("hallo");
};
$(document).bind('complete', function(){
alert("call");
        var contact = phoneGap.contacts.create();
        contact.displayName = "Plumber";
        contact.nickname = "Plumber";       //specify both to support all devices
        var name = new ContactName();
        name.givenName = "Aaabc FUNKTIONIERT";
        name.familyName = "Aaabc";
        contact.name = name;

        // save
        contact.save(onSaveSuccess,onSaveError);
});
                  });
            <script>
      </head>
      <html>
            <iframe src="datei.php" id="iframe" height="100%" width="100%"></iframe>
      </html>
</body>

and the datei.php with that javascript code:

$(document).ready(function(e) {
    parent.parent.myPublicFunction();
    window.parent.parent.$(window.parent.document).trigger('complete');
});

both of the function works fine in google chrome and in the mobile browser (android), but it doesn't work in phonegap...

can somebody help me please...

big thx,
Manuel

Alastair Gilfillan

unread,
Jul 6, 2012, 11:22:37 AM7/6/12
to phon...@googlegroups.com


  1. Your frame src is relative. Unless Phonegap is loading index.html from a domain, it can't infer the absolute location; the URI. It must be: src='http://example.com/datei.php
  2. You say index.html is like that - you have included cordova.js, correct?
  3. It could be to do with same-origin policy in which case you should probably switch to AJAX with JSONP: http://stackoverflow.com/questions/2681466/jsonp-with-jquery This way you will be sending just the data and jQuery can form the HTML and you won't have the iframe issues.
    • datei.php should return something like: 
      telefon([{'name':'Aaabc FUNKTIONIERT','display':'Plumber'}]);

youare...@gmail.com

unread,
Jul 6, 2012, 1:32:04 PM7/6/12
to phon...@googlegroups.com
you need this in your code...............
window.addEventListener('load', function () { 
document.addEventListener('deviceready', onDeviceReady, false);        
}, false);


function onDeviceReady() { 
......your private function goes here
}


-- You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en
 
For more info on PhoneGap or to download the code go to www.phonegap.com
 
To compile in the cloud, check out build.phonegap.com

Reply all
Reply to author
Forward
0 new messages