使用js更改UIWebView的href值

时间:2012-01-15 18:09:06

标签: iphone objective-c ios ipad uiwebview

我有以下代码:

NSString *stripLink = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href=%@", pt.x, pt.y, @"http://www.test.com"];
NSLog(@"JS IS %@", stripLink);
[self stringByEvaluatingJavaScriptFromString:stripLink];

NSString *testHref = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href", pt.x, pt.y];
NSLog(@"FINAL HREF IS %@", [self stringByEvaluatingJavaScriptFromString:testHref]);

然而,最终的URL始终是旧的,为什么会这样? ?这是什么问题?

1 个答案:

答案 0 :(得分:0)

我认为您忘记将新网址括在引号中。试试这个,并告诉我们:

NSString *stripLink = [NSString stringWithFormat:@"document.elementFromPoint(%f, %f).parentNode.href='%@'", pt.x, pt.y, @"http://www.test.com"];

(请参阅'%@'周围的'引号')