I have a block of javascript code for a like button with likebtn.com. I want to put this in iOS. I have been searching the web for hours but I couldn't find any way to simply use my javascript code in my xcode project. I need help making a vote button. Thanks in advance
            Asked
            
        
        
            Active
            
        
            Viewed 87 times
        
    0
            
            
        - 
                    do you want to load the URL? or wants to write code? – Mohit Aug 19 '14 at 11:36
- 
                    i have a javascript code that makes a like button. i want it to make that button in an ios app – deno Aug 19 '14 at 11:38
- 
                    Did you try any code? or anything ? – Mohit Aug 19 '14 at 11:39
- 
                    i tried everything i found on the web but i couldnt find any tutorial to specifically use a javascript code in ios – deno Aug 19 '14 at 11:40
- 
                    please put some code that you tried – Mohit Aug 19 '14 at 11:42
- 
                    i followed this tutorial but i only had 'Hello World' and nothing more. I need more specific explanation on how to use a javascript code: http://sketchytech.blogspot.com.tr/2012/04/uiwebview-javascript-and-objective-c.html – deno Aug 19 '14 at 11:46
2 Answers
0
            
            
        From interface builder drag UIWebView to your viewController.
Press ctrl and drag UIWebView connection to your h file to make IBOutlet.

Than in your m file you can access your UIWebView to load page content Make sure to check https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#jumpTo_2 for full documentation

 
    
    
        user2432612
        
- 188
- 1
- 7
- 
                    
- 
                    As an addendum: you might need to use stringByEvaluatingJavaScriptFromString:, see the reference [here](https://developer.apple.com/library/ios/documentation/uikit/reference/UIWebView_Class/Reference/Reference.html#//apple_ref/occ/instm/UIWebView/stringByEvaluatingJavaScriptFromString:) – andreamazz Aug 19 '14 at 11:46
- 
                    thanks very much for your help but i do not want to load page content i just want a javascript code to run – deno Aug 19 '14 at 11:51
- 
                    @deno But you also want to display HTML content generated from javascript (if i get it right) so you must use UIWebView – – user2432612 Aug 19 '14 at 12:22
- 
                    
- 
                    You can put js inside file and load id to a webview http://stackoverflow.com/questions/7063276/how-to-load-local-html-file-into-uiwebview or you can put your code in NSString and load it like [mWebView loadHTMLString:my_string baseURL:nil]; – user2432612 Aug 19 '14 at 12:36
0
            
            
        If you don't need the web view, you can execute javascript code using JavaScriptCore https://developer.apple.com/library/mac/documentation/Carbon/Reference/WebKit_JavaScriptCore_Ref/_index.html
Some examples: http://www.bignerdranch.com/blog/javascriptcore-and-ios-7/ http://www.bignerdranch.com/blog/javascriptcore-example/
 
    
    
        YarGnawh
        
- 4,574
- 6
- 26
- 37
 
    