iphone - 使用js更改UIWebView的href值

标签 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 总是旧的,这是为什么呢? ?这里有什么问题?

最佳答案

我想您忘记了用引号将您的新 URL 括起来。试试这个,然后告诉我们:

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

(查看 '%@' 周围的“引号”?)

关于iphone - 使用js更改UIWebView的href值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8872047/

相关文章:

iphone - MPMediaPickerController.showsCloudItems 似乎什么都不做

iphone - 游戏中心不可用时如何同步分数?

java - 如何使用 Java JDK 1.7 在我的第三方服务器上验证 GKLocalPlayer?

iphone - 录音机适用于 iPhone 3GS,但不适用于 iPhone 3G

iphone - 触摸时UISearchBar崩溃

iOS8 自定义键盘访问用户默认值而不请求开放访问

ios - 禁止在 WKWebView ios 中加载图像

objective-c - 弹出一个以模态方式呈现的 UINavigationController

iphone - 无法在 Xcode 中选择文件所有者

ios - 使用 LibMusicXML 在 IOS 中创建 musicXML 浏览器