Search code examples
javascriptjqueryioscordovansfilemanager

Can i make a html file in Documents directory which accesses jquery and cordova in the app bundle?


I am building a html file which is stored in

[[PROJ UserDirectory] stringByAppendingPathComponent:@"tmp_Form_File.html"]

and inside of the file "tmp_FOrm_File.html" it is being dynamically built. Body shows up correctly but the JS will not execute.

I was trying to do:

NSString * cordova_path = [[NSBundle mainBundle] oathForResource:@"cordova-2.2.0" ofType:@"js" inDirectory:@"html"]
NSString = [[@"<script type=\"text/javascript\" src=\"" stringByAppendingString:cordova_path] stringByAppendingString:@"\"></script>"];

and similarly for jquery.

My issue is that i dont think that when I load the htmlfile into a webView that it gets the data accordingly.

I tested the strings, and they look sound:

<script type="text/javascript" src="/var/mobile/Applications/[DATA]/PROJ.app/html/cordova-2.2.0.js"></script><script type="text/javascript" src="/var/mobile/Applications/[DATA]/PROJ.app/html/jquery-1.7.2.min.js"></script><script type="text/javascript">$(function(){ alert("test"); });</script>

1) Am i doing it wrong? if So, how do i resolve this?

2) Would it be better to through ios copy the html directory in the bundle to Documents? If so, how?

Edit: Temporarily removed the jquery references, jquery and cordova. just used pure javascript, and it will alert correctly. So that means there is something wrong with the src being in the Bundle.


Solution

  • I couldnt reference it atm, but i resolved it this way: - I copied the contents of [BUNDLE]/html to Documents....

        NSString * sourcePath = [[[NSBundle mainBundle] pathForResource:@"cordova-2.2.0" ofType:@"js" inDirectory:@"html"] stringByDeletingLastPathComponent];
        NSString * documentDirectory = [AssetInspectorFileManager UsersDirectory];
    
    • adjusted the src of the javascript.

      < script type=\"text/javascript\" src=\"cordova-2.2.0.js\">

      < script type=\"text/javascript\" src=\"jquery-1.7.2.min.js\">

    • Closed a missing parenthese

      " $(\"div.container\").css(\"z-index\",1;"

    became

     "   $(\"div.container\").css(\"z-index\",1);"
    
    • Coomenting is not good to do for this, as when you write data out such as:

      $(this).click(function(){//[THIS IS A COMMENT] alert("hi");});

    So you have to adjust for that sort of issue.