stringByEvaluatingJavaScriptFromString在iOS 6中不起作用 [英] stringByEvaluatingJavaScriptFromString is not working in iOS 6

查看:207
本文介绍了stringByEvaluatingJavaScriptFromString在iOS 6中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现问题仅发生在iOS 6上,但在iOS 6以下版本正常运行。

I am seeing problem happen only on iOS 6 but working fine on below iOS 6 version.

我的应用程序正在从链接加载图像,该链接需要使用Javascript扩大其图像像素以填充UIWebView的大小。链接图像最初是像素140x24。

My app is loading image from a link which need to enlarge its image pixels to populate within size of UIWebView by using Javascript. The link image is originally in pixels 140x24.

我看到它正在线上运行,但图像没有使用iOS 6模拟器进行扩展。它在iOS 5模拟器中工作。请帮忙。

I see it is running over the line, but the image not being scaled up using iOS 6 simulator. It does work in iOS 5 simulator. Please help.

(void)webViewDidFinishLoad:(UIWebView *)webView {

  [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName(\"img\")(0).height=\"30\";document.getElementsByTagName(\"img\")(0).width=\"280\";"];

}


推荐答案

语法在javascript中获取数组的第n个元素是使用方括号,而不是括号。所以使用 document.getElementsByTagName(img)[0] 而不是 document.getElementsByTagName(img)(0)

The syntax in javascript to get the n-th element of an array is using square braces, not parentheses. So use document.getElementsByTagName("img")[0] not document.getElementsByTagName("img")(0).

不知道为什么它在iOS5中工作,在iOS6中WebKit可能更严格...

附加提示:要调试iOS6上的javascript错误,新功能非常简单:

Additional tip: to debug javascript errors on iOS6, a new feature makes it very simple:


  • 转到设置iPhone中的应用程序,输入Safari设置并点击底部的高级,然后从那里启用WebKit Inspector

  • 显示要调试的页面屏幕(即启动您的应用程序并转到包含WebView的屏幕以使其可见)

  • 通过USB线将iPhone插入Mac

  • 在Mac上打开Safari.app,转到开发菜单(1),选择带有iPhone名称的菜单项,然后在子菜单中选择您的应用程序。

  • Go to the "Settings" application in your iPhone, enter the "Safari" settings and tap on "Advanced" at the bottom, then enable the "WebKit Inspector" from there
  • Display your page to be debugged on the screen (i.e. launch your app and go to your screen that contains the WebView to make it visible)
  • Plug your iPhone to your Mac via your USB cable
  • Open Safari.app on your Mac, go to the "Development" menu (1), select the menu item with the name of your iPhone and select your application in the submenu.

然后,您就可以调试自己的网页了你的iPhone使用Mac上强大的Web Inspector,可以查看javascript控制台,DOM树等。

You will then be able to debug your web page presented in your iPhone using the powerful Web Inspector from your Mac, and can look into the javascript console, the DOM tree, etc.

(1)如果你不喜欢在Mac上的Safari中有开发菜单,您可以在Safari应用程序的高级首选项选项卡中启用它。

这篇关于stringByEvaluatingJavaScriptFromString在iOS 6中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆