Skip to content

Instantly share code, notes, and snippets.

@laiso
Created April 27, 2011 08:22
Show Gist options
  • Save laiso/943911 to your computer and use it in GitHub Desktop.
Save laiso/943911 to your computer and use it in GitHub Desktop.
#import <UIKit/UIKit.h>
@interface UIWebViewBaseTest : NSObject <UIApplicationDelegate> {
UIWebView* web;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) UIWebView* web;
@end
@implementation UIWebViewBaseTest
@synthesize window=_window;
@synthesize web;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self.window makeKeyAndVisible];
web = [[UIWebView alloc] initWithFrame:self.window.frame];
[self.window addSubview:web];
UIButton* b = [UIButton buttonWithType:UIButtonTypeContactAdd];
b.frame = CGRectMake(0, 0, 100, 100);
[b addTarget:self action:@selector(execCode) forControlEvents:UIControlEventTouchDown];
[self.window addSubview:b];
return YES;
}
-(void)execCode
{
NSString* script =
@"<script>"
@"window.location = 'http://hamachiya.com/junk/gmail_fortune.html';"
@"</script>";
[web loadHTMLString:script baseURL:nil];
/*
NSString* script =
@"window.location = 'http://hamachiya.com/junk/gmail_fortune.html';"
NSString* result = [web stringByEvaluatingJavaScriptFromString:script];
NSLog(@"%@", result);
*/
/*
// 危険なコードを返す
[web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/test"]]];
*/
}
- (void)dealloc
{
[_window release];
[web release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment