Childbrowser no longer works for local files on iOS. #45

SimonClark opened this Issue Nov 25, 2011 · 7 comments


None yet

5 participants


Since upgrading to xCode 4.2, phonegap 1.2.0, iOS 5 (which I did all a flurry in one day), I can no longer use childbrowser with local files in the www folder. Works fine with http://, https://, just not local filesystem.


Thanks to mrFloyd on irc, it seems that you now need to give absolute paths for the child browser. This function will convert for you.:

getLocalPath: function(pageName)
    var location = document.location.href;
    location = location.split('index.html').join(pageName);
    location = location.split(' ').join('%20');
    return location;

Where do you place this code? In the ChildBrowser.js?



You can put it anywhere in javascript that you can access it. ChildBroswer.js is fine, you just need to call the function to convert your path before you make the childBrowser call.


Thanks! I'll keep this code handy. I haven't been able to build it successfully yet.


In iOS 5.1 and Cordova 1.9,, the document.location.href is about:blank.

I tried http:// as well as file:// for loading a file in the root folder without any success. :/

Is there a some one who got this to work?


@becomingGuru I got this to work and successfully displaying a PDF in the most recent version of Cordova.

Are you sure you're calling getLocalPath before you open the ChildBrowser and that your file is in the www folder?

If yes to both the only other thing I can think is to add the file to the www/ folder by dragging it to xCode.


the 'getLocalPath' function worked for me and I was successfully able to display the PDF.

I'd like to add a slight clarification here. The above sample code assumes that you'll be invoking that function from your 'index.html' page. By chance if you invoke it from a different page, which I did, just replace index.html with your page name:

eg: pagename --> demo.html
Then replace the code:
location = location.split('index.html').join(pageName);
location = location.split('demo.html').join(pageName);

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment