Access objc variable from javascript?

Discussion in 'iPhone/iPad Programming' started by Danneman101, Feb 23, 2009.

  1. macrumors 6502

    Joined:
    Aug 14, 2008
    #1
    How can I access an objc variable (say an integer) from the javascript-code of a html-page within a uiwebview?

    Is it even possible?
     
  2. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #2
  3. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #3
    There is very little documentation on it, and no examples to mimic/alter.

    Was your solution to call the javascript and pass along the variabel as a parameter?

    Pseudocode:
    Code:
    - (NSString *)stringByEvaluatingJavaScriptFromString:(NSString *)myJSFunction(returnParameter)
    
     
  4. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #4
    Yup.

    Code:
    [webview stringByEvaluatingJavaScriptFromString:
    	[NSString stringWithFormat:@"document.write(\"%d\");", var]];
    etc.
     
  5. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #5
    Alright, Im getting somewhere - thanks for your help :)

    Finally, just let me get this straight: in the code you substitute the %d with var?
     
  6. macrumors 6502a

    Joined:
    Oct 24, 2008
    Location:
    Cambridge
    #6
  7. thread starter macrumors 6502

    Joined:
    Aug 14, 2008
    #7
    Great - thanks again for the help :) Much appreciated!
     

Share This Page