偶然用捞月狗看炉石卡组,发现他们的卡组界面都是h5界面.于是把九个职业卡组的网址搞过来.利用WebView加载.但是点击的时候发现并没有效果.查看网页的源代码
发现卡组详情的点击事件是
<li class="arrow-r" οnclick="javascript:location.href='laoyuegou://open?title=蓝白T7猎&&url=http%3A%2F%2Fh5v2.laoyuegou.com%2FhearthStone%2FCardGroup%2FplayerId%2F61486%2FgroupId%2F166%2Fself%2F1%2FnowUrl%2Fhttp%25253A%25252F%25252Fh5v2.laoyuegou.com%25252FhearthStone%25252Fcards%25252Fid%25252F61486%25252Fsort%25252F0%25252Ftype%25252F0%25252Fspeed%25252F0%25252Fclass%25252Fhunter%25252Fajax%25252F0%25252Fself%25252F1%25252FpageNow%25252F1.html%25253Fappver%25253D2p.3.2%252526appfrom%25253D%2Fly%2F0.html%3Fappver%3D2.3.2%26appfrom%3D';">
onclick事件里边就是点击的方法,但是怎么取得这个事件呢.从网上查了一些方法等到了UIWebView又一个叫
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{}
的方法.具体作用是当html页面的JS事件运行的时候执行的方法
-(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{
NSString * requestString = [[request URL]absoluteString];
// requestString先是整体的,点击后变成部分的
// NSLog(@"%@",requestString);
// 如果前缀为 laoyuegou://open 则进行跳转
if ([requestString hasPrefix:@"laoyuegou://open"]) {
Detail_2_ViewController * d2v = [[Detail_2_ViewController alloc]init];
d2v.urlStr = requestString;
[self.navigationController pushViewController:d2v animated:YES];
return YES;
}
return YES;
}
运行知道 requestString开始是整个的网址,点击tableView的时候requestString变成了javascript:location.href里面的语句
laoyuegou://open?title=%E8%93%9D%E7%99%BDT7%E7%8C%8E&&url=http%3A%2F%2Fh5v2.laoyuegou.com%2FhearthStone%2FCardGroup%2FplayerId%2F61486%2FgroupId%2F166%2Fself%2F1%2FnowUrl%2Fhttp%25253A%25252F%25252Fh5v2.laoyuegou.com%25252FhearthStone%25252Fcards%25252Fid%25252F61486%25252Fsort%25252F0%25252Ftype%25252F0%25252Fspeed%25252F0%25252Fclass%25252Fhunter%25252Fajax%25252F0%25252Fself%25252F1%25252FpageNow%25252F1.html%25253Fappver%25253D2.3.2%252526appfrom%25253D%2Fly%2F0.html%3Fappver%3D2.3.2%26appfrom%3D
这样就可以得到卡组的详细内容了.其中具体的网址是"url="后面的内容,里面的几个符号做了更改
: %3A
/ %2F
? %3F
= %3D
& %26
这样就可以用字符串的变化就可以得到url的具体内容
http://h5v2.laoyuegou.com/hearthStone/CardGroup/playerId/61486/groupId/166/self/1/nowUrl/http%25253A%25252F%25252Fh5v2.laoyuegou.com%25252FhearthStone%25252Fcards%25252Fid%25252F61486%25252Fsort%25252F0%25252Ftype%25252F0%25252Fspeed%25252F0%25252Fclass%25252Fhunter%25252Fajax%25252F0%25252Fself%25252F1%25252FpageNow%25252F1.html%25253Fappver%25253D2.3.2%252526appfrom%25253D/ly/0.html?appver=2.3.2&appfrom=
可以复制在浏览器里打开,发现闪了一下卡组就马上跳转到 "laoyuegou://"开始的网址了,说找不到对应程序.可能在源码里写了浏览器的类型吧.如果在模拟器里则可以正常的打开.
更新:最后研究出来怎么正常在浏览器里打开了.因为网址的最后有一句代码
if (!query.lygs){windows.location=laoyuegou://showShare?....}
如果上传的参数不存在的话,就定位到这个网址.把!去掉就不跳转了.另外有的还是根据请求头User-Agent来判断是移动端还是网页端打开.
最后研究了一下怎么把代码传到github上.参考了http://www.jianshu.com/p/dd99a827927f的介绍.因为我电脑之前装过github的客户端.主要是"文件的名字必须与工程的名字相同"纠结了半天.最后终于上传上去了.代码地址:https://github.com/YoungFroever/HeartStone