is it possible to use iframe in UIWebView?
Asked Answered
E

2

9

i want to add a facebook like button in my app. in developer.facebook.com i couldn't fine anything about that. is it possible to use iframe created by facebook like button in UIWebView? it think if its possible then i can add a UIWebView in my app which use that iframe. thanx. please write some example code.

Edo answered 2/3, 2011 at 13:8 Comment(0)
K
9

Yes that is possible you can use the iframe in webview. You need to load the webview with the HTML string. You can also find the related code of HTML for iframe if you search over the net. Moreover you can also use javascript, in webview using the method stringByEvaluatingJavaScript: of UIWebview.

Keelin answered 2/3, 2011 at 13:30 Comment(0)
G
16

Yes it is possible, I am using iFrame to load youtube Video inside the app.

Following simple steps will guide you to achieve it.

Step 1 : Create a UIWebView in xib
Step 2 : Connect it to your ViewController's .h file. (I am referring it as _wevView in my project).
Step 3 : Create a method embedYouTube in your ViewController's .m file.

-(void)embedYouTube {
    // Read create a NSString object with iframe
    NSString *embedHTML = @"<iframe width=\"300\" height=\"250\" src=\"http://www.youtube.com/embed/rOPI5LDo7mg\" frameborder=\"0\" allowfullscreen></iframe>";

    // Initialize the html data to webview
    [_webView loadHTMLString:embedHTML baseURL:nil];

    // Add webview to your main view
    [self.view addSubview:_webView];

}

Step 4: Add the webview to your main view by by making a call to the method embedYouTube inside viewDidLoad

[self embedYouTube];

Step 5: Compile and run the app. You should be able to view the YouTube player embedded in the page.

Guideline answered 10/4, 2013 at 5:3 Comment(1)
however, when you playback, it will go to full screen, is there any way to directly play within the webview?Dashtikavir
K
9

Yes that is possible you can use the iframe in webview. You need to load the webview with the HTML string. You can also find the related code of HTML for iframe if you search over the net. Moreover you can also use javascript, in webview using the method stringByEvaluatingJavaScript: of UIWebview.

Keelin answered 2/3, 2011 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.