Created
May 8, 2015 22:35
-
-
Save lidio601/759775aa961d81f30ccf to your computer and use it in GitHub Desktop.
Objective-C: web view on a ios app. test of javascript injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript"> | |
function doWork() { | |
document.getElementById('result').value = genSeq(); | |
} | |
</script> | |
</head> | |
<body> | |
<h1>it works!</h1><br /> | |
<button onclick="doWork();">Run</button><br /> | |
<textarea cols="30" rows="10" id="result"></textarea> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.h | |
// testWebView | |
// | |
// Created by Fabio Cigliano on 21/02/13. | |
// Copyright (c) 2013 Fabio Cigliano. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface ViewController : UIViewController | |
@property (nonatomic,weak) IBOutlet UIWebView *webview; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// TestWebviewVC.m | |
// testWebView | |
// | |
// Created by Fabio Cigliano on 21/02/13. | |
// Copyright (c) 2013 Fabio Cigliano. All rights reserved. | |
// | |
/* | |
http://stackoverflow.com/questions/8848311/how-to-inject-javascript-in-my-uiwebview | |
http://stackoverflow.com/questions/10010342/clicking-on-a-link-inside-a-webview-that-will-trigger-a-native-ios-screen-with | |
http://stackoverflow.com/questions/4645414/how-can-i-load-a-local-html-file-into-the-uiwebview | |
http://stackoverflow.com/questions/1662565/uiwebview-finished-loading-event | |
*/ | |
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
// Do any additional setup after loading the view, typically from a nib. | |
[[self webview] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
- (void)webViewDidFinishLoad:(UIWebView *)webView { | |
[[self webview] stringByEvaluatingJavaScriptFromString:@"var genSeq = function() { return new Array(0,0,0); };"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment