您的位置:首页 > 移动开发

iOS之UIWebView的使用——嵌套HTML与JavaScript

2015-01-05 15:02 357 查看
1、.h

#import <UIKit/UIKit.h>

@interface FKViewController : UIViewController
@property (strong, nonatomic) IBOutlet UIWebView *webView;

@end

2、.m
#import "FKViewController.h"

@interface FKViewController ()

@end

@implementation FKViewController

- (void)viewDidLoad
{
[super viewDidLoad];
NSMutableString* sb = [[NSMutableString alloc] init];
// 拼接一段HTML代码
[sb appendString:@"<html>"];
[sb appendString:@"<head>"];
[sb appendString:@"<title> 欢迎您 </title>"];
[sb appendString:@"</head>"];
[sb appendString:@"<body>"];
[sb appendString:@"<h2> 欢迎您访问<a href=\"http://www.crazyit.org\">"];
[sb appendString:@"疯狂Java联盟</a></h2>"];
// HTML代码中支持JavaScript脚本
[sb appendString:@"<script language='javascript'>"];
[sb appendString:@"alert('欢迎使用UIWebView');</script>"];
[sb appendString:@"</body>"];
[sb appendString:@"</html>"];
// 加载、并显示HTML代码
[self.webView loadHTMLString:sb
baseURL:[NSURL URLWithString:@"http://www.fkit.org"]];
}
@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iOS UIWebView