-1

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.

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129

2 Answers2

0

This is happening because your references are not working. When you want your HTML to be rendered in webview with some relative paths inside it, you have add it like using the option "Create folder references for added folder".

If this html pages are not going to fetch and store any data, then keep it in bundle, otherwise copy them to Library or document's folder in Appdelegate.

Hope this helps!

Like this

Urmil Setia
  • 159
  • 1
  • 9
  • Yea, as per my answer I just created, also seemed to sort of follow your steps. I end up having to copy from Bundle to Documents. I dont think the first part was working correctly, so i just moved it. – Fallenreaper Dec 11 '12 at 18:02
  • The first part didnt for some reason. With the post I did, I broke it up, and gave code samples. – Fallenreaper Dec 11 '12 at 18:47
0

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.

Fallenreaper
  • 10,222
  • 12
  • 66
  • 129