I am building an app and because of my missing knowledge of java and Xcode I decided to make this app in HTML,PHP,CSS & javascript(jquery). Now I'm facing the problem of getting this app to the different devices and I want to use PhoneGap for that. I placed an index.html inside the server for the app and there is an iframe placed inside and nothing more. Is it still possible for me to get access to the media storage and send PHPdata back and forth while having an iframe as a bridge between PhoneGap on android and my website on its web server? Can I access the camera of the device?
问题:
回答1:
The short answer: No, and you shouldn't try that.
The long answer (And the safer one) is to use postMessage
as described in MDN, do it in a different way could cause inconsistency between devices (Remember how fragmented is android and how painful could be the backward compatibility with 4.3 and below)
So, you could get the iFrame element and then post a message like
otherWindow.postMessage(InfoToSend, "*");
In the same way, you could listen to that event inside the frame:
window.addEventListener("message", receiveMessage, false);
This will no cause cross-frame issues and it will be the safer way to pass information between the frames, this work in both directions, so you could ask (From inside your iFrame) to use some native feature (plugin), listen to this event in your device main app, executed what you need and after that send a postMessage (from your app) to your iFrame with the result (a base64
img for example)
If you are trying to pass the window.cordova
the instance or something similar, it won't work, so you will need to establish a conversation between the iFrame
and the window.top
frame.