iOS webview 和 js 交互
来源:互联网 发布:布比网络 编辑:程序博客网 时间:2024/06/05 16:30
1.先上一段 html 代码
<html>
<head>
<meta http-equiv="Content-Type"content="text/html; charset=utf8">
</head>
<body>
<h1>这是一段内容</h1>
<input type="button"value="测试" onclick="check()" />
<input type="button"value="测试2"onclick="check2()"/>
</body>
</html>
2. js 代码
function loadURL(url) {
var iFrame;
iFrame = document.createElement("iframe");
iFrame.setAttribute("src", url);
iFrame.setAttribute("style","display:none;");
iFrame.setAttribute("height","0px");
iFrame.setAttribute("width","0px");
iFrame.setAttribute("frameborder","0");
document.body.appendChild(iFrame);
//发起请求后这个iFrame就没用了,所以把它从dom上移除掉
iFrame.parentNode.removeChild(iFrame);
iFrame =null;
}
function check() {
loadURL("lichongyang:abc");
}
function check2() {
loadURL("lichongyang2:abc");
}
3.当js 调用 iOS 的时候 通过上面的js 代码 会重定向一个 请求的url 在
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
NSURL * url = [request URL];
if ([[urlabsoluteString] rangeOfString:@"abc"].location!=NSNotFound) {
UIAlertView * alertView = [[[UIAlertViewalloc] initWithTitle:@"test"message:[url absoluteString]delegate:nilcancelButtonTitle:@"OK"otherButtonTitles:nil]autorelease];
[alertViewshow];
return NO;
}
//获取当前页面的title
//self.title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
return YES;
}
- iOS webview 和 js 交互
- iOS解析---WebView和js交互原理
- iOS解析---WebView和js交互原理
- iOS解析---WebView和js交互原理
- iOS webView和JS简单交互处理
- iOS中WebView和JS的交互
- iOS中webview和js的交互
- iOS中webView和JS交互
- iOS webView js和Objective c交互
- iOS WebView JS 交互
- WebView和js交互
- WebView和js交互
- webview和js交互
- webview和js 交互
- webview和js交互
- WebView和JS交互
- Webview和js交互
- iOS webView 与js交互
- Oracle数据库再次安装
- error LNK2001: unresolved external symbol __imp__SetupDiGetDeviceInterfaceDetailA@24
- Scala各种类型实战
- 如何写好技术简历 —— 实例、模板及工具
- Qt使用的一些总结
- iOS webview 和 js 交互
- Qt4.8.6插件化编程例程--仅供参考
- ios 微博分享
- HTML中引号多层嵌套的问题
- nyoj757 期末考试【队列】
- EJB学习笔记三(有状态和无状态SessionBean的区别)
- Number of Digit One
- Algorithm——QuickSort
- background:url(imagepath)不能显示图片