- click 事件还是 tap 事件?
- Zepto 的 show/hide 有时不靠谱
- Android 下的跨域问题
- pushState 调用失败也属于跨域问题
- 对于无需缩放的页面,禁用双击缩放功能,
- 引入 Zepto 框架的 tap 事件,
- Zepto 趁着 JQuery 在移动互联网市场历史包袱重的机会,搞了一套轻量级类 JQuery 框架的代码,核心代码千行,从而迅速成为移动端 DOM 操作库的首选。
- Zepto 提供了一个 touch 库,在载入 Zepto 后为 document 绑定 touchstart、touchmove、touchend 事件,根据手指 x、y 值的位置,判断方向从而触发 tap、doubleTap、swipeLeft 等事件。
- 原本没有 tap 事件,Zepto tap 是用 touchstart 和 touchend 模拟出来的。
- 引入 Fastclick 的 click 事件,
- FastClick 是 FT Labs 专门为解决移动端浏览器 300 毫秒点击延迟问题所开发的一个轻量级的库。简而言之,FastClick 在检测到
touchend
事件的时候,会通过 DOM 自定义事件立即触发一个模拟click
事件,并把浏览器在 300 毫秒之后真正触发的click
事件阻止掉。
fx_methods | Animated show , hide , toggle , and fade*() methods. |
---|
fx_methods show() and hide() add unnecessary CSS properties on non-animated DOM nodes
|
When you add fx_methods to your Zepto, the show() and hide() methods are overriden with methods that also call animate.
Even in the case of undefined speed (normal show), animate still adds many CSS properties to the shown/hidden nodes.
These unexpected CSS rules can interfere with the page CSS (in my case, it has changed the positioning of my child fixed DIVs).
|
- 继续引入 Zepto 的 fx_methods,但按 madrobby 所说,没有定义 speed 时,仅调用原生的 show;
- 从 Zepto 官方的 改为
- 如 0x00 和本小节所描述的问题,不要引入 Zepto 的 touch 和 fx_methods 模块。
- 只引入 zepto+event+ajax+form+ie 基本模块
- Android 的 WebView 通过 file:// 协议加载本地的 HTML5 模板文件。本地文件的 JS 向远端发送 AJAX 请求,受到同源策略的限制,譬如你可能会看到“XMLHttpRequest cannot load file://…… Origin null is not allowed by Access-Control-Allow-Origin.”的错误提示,即当你的 URI 是 file:// 时,源域名(origin)为空。
- 借用 difcareer 的评论:Web 应用程序能且只能使用 XMLHttpRequest 对象向其加载的源域名发起请求,而不能向任何其他域名发起请求,但 HTML5 允许 AJAX 跨域向其他域名发起请求,但是不能获取服务器端响应。
- iOS 下无此跨域问题。
- 如果是 GET 请求:
- 可以通过 JSONP 来解决跨域问题;
- 如果是 POST 请求:
- 由 App 原生代码发起网络操作,成功后回调 JS。
- 利用 HTML5 的“Cross-Origin Resource Sharing(CORS,跨域资源共享)”新特性,在服务器端响应头里设置:Access-Control-Allow-Origin 头域;
- 不限制来源,Access-Control-Allow-Origin: *
- 限制来源域,Access-Control-Allow-Origin: http://xxx.com
- 具体设置参考 http://enable-cors.org/;
- 这需要浏览器支持;
- SmdCn 提及,『在某些版本的 Android 浏览器中,因为缓存的原因,第一次 CORS 正常,但第二次会失效。对此,可以通过在响应头中增加 Cache-Control: no-cache 来解决』。
-
设置 Android 的 WebView 如下 settings 参数为 True:
if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){
webView.getSettings().setAllowUniversalAccessFromFileURLs(true);
}
由此允许通过 file url 加载的 Javascript 可以访问其他的源,包括其他的文件和 http/https 等源。这个设置在 JELLY_BEAN 以前的版本默认是允许,在 JELLY_BEAN 及以后的版本中默认是禁止的。According to the documentation for setAllowFileAccessFromFileURLs and setAllowUniversalAccessFromFileURLs, they used to be set to true for ICS and older. Starting in JellyBean they turned it off. If you are trying to load a local JS file from a local HTML page, then you'll need to enable these. – Steven