Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm building an app using OpenID, now I want to get access token, please go through this given link

http://www.stevesaxon.me/posts/2011//window-external-notify-in-ios-uiwebview

In that link javascript function is given

<script type=\"text/javascript\">

    window.external =

    {
        'Notify': function(s) { document.location = 'acs://settoken?token=' + s; },
        'notify': function(s) { document.location = 'acs://settoken?token=' + s; }
    };

</script>

How to load this javascript in UIWebview?

share|improve this question

3 Answers

up vote 2 down vote accepted

The class UIWebView has a method called stringByEvaluatingJavaScriptFromString which you can use to load javascript code to a webview.

I use this method to execute javasctipt on my webview:

-(void) runjs:(NSString *)code
{
    @try 
    {
        if (webview)
            [webview stringByEvaluatingJavaScriptFromString: code];      
    }
    @catch (NSException *exception) 
    {
    }
}
share|improve this answer
Thanks aleixventa – user2315206 Apr 24 at 11:36

Check the UIWebView method called:

stringByEvaluatingJavaScriptFromString:(NSString *)script;

NSString *result = [_webView stringByEvaluatingJavaScriptFromString:(@"alert('Hi')")];
share|improve this answer
Thanks for valuable reply Avi – user2315206 Apr 24 at 11:20
You're welcome! – Avi Tsadok Apr 24 at 11:21

You can use this method to call the javascript from html to iOS webview

[self.webView stringByEvaluatingJavaScriptFromString:@"my_html_function();"];

this may help you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.