简体   繁体   English

jQuery Mobile 1.4.5似乎未在ipad上调用javascript

[英]JQuery Mobile 1.4.5 does not seem to invoke javascript on ipad

Using JQuery mobile 1.4.5 ( https://jquerymobile.com/ ) 使用JQuery mobile 1.4.5https://jquerymobile.com/

Ironically, everything works on desktop browsers, but I cannot seem to get anything to work when testing on an iPad ... 具有讽刺意味的是,一切都可以在桌面浏览器上运行,但是在iPad上进行测试时,我似乎无法正常工作...

My stripped down page (HTML) contains the following: 我的精简页面(HTML)包含以下内容:

<div data-role="content">
 <script src="test.js"></script>    
 <script>
  $( document ).on( 'pagecreate', function( event ) { do_something(); });
 </script>
</div>

The file "test.js", contains the following code: 文件“ test.js”包含以下代码:

function do_something() {

   alert('here in do_something()');

}

When testing on an iPad, all I get is a grey circle with a "spinning comet" rotating around in the circle and the page never even renders (Yes, I tried rebooting the iPad, clearing browser history/data, etc). 在iPad上进行测试时,我得到的只是一个带有“旋转彗星”的灰色圆圈,该圆圈在圆圈中旋转,页面甚至从未呈现(是的,我尝试过重新启动iPad,清除浏览器历史记录/数据等)。

On all other browsers, I get the alert. 在所有其他浏览器上,我得到警报。

Ultimately, I am trying to load google maps into the page along with the javascript I need to manipulate various DOM elements as well as manipulate the map -- which I CAN do and is working on all other browsers -- just can't seem to get anything to work when testing on an iPad (I do not know how to view source or console messages via iPad Safari, which makes debugging a nightmare). 最终,我试图将google map以及需要操作各种DOM元素以及javascript的javascript加载到页面中-我可以做到并且正在所有其他浏览器上工作-似乎似乎无法在iPad上进行测试时,任何事情都可以工作(我不知道如何通过iPad Safari查看源消息或控制台消息,这使调试成为噩梦)。

ANY suggestions would be helpful. 任何的意见都将会有帮助。

Thanks in advance. 提前致谢。

First of all, you missed some important information like, were "all other browsers" running on your desktop machine or are we talking about other mobile devices? 首先,您错过了一些重要信息,例如台式机上是否正在运行“所有其他浏览器”,或者我们是否在谈论其他移动设备? This is extremely important. 这是非常重要的。

As you can see spinner that would mean jQuery Mobile and jQuery are loaded. 如您所见,微调器意味着将加载jQuery Mobile和jQuery。

If they were successfully running on your desktop computer then you may check these: 如果它们已在您的台式计算机上成功运行,则可以检查以下内容:

  • Make sure none of your content is running on or from localhost. 确保没有任何内容在本地主机上运行或从本地主机运行。 This will work just fine on desktop computers, but if you try to test it on any other device it will fail. 这将在台式计算机上正常工作,但是如果您尝试在任何其他设备上对其进行测试,则它将失败。
  • Make sure you are not using an absolute path in your jQM application, this will also fail on any remote device. 确保您在jQM应用程序中未使用绝对路径,这在任何远程设备上也会失败。 I presume something similar may be the case as jQM is not able to show the first page 我想可能是类似的情况,因为jQM无法显示第一页
  • You will need to use a remote debugging feature. 您将需要使用远程调试功能。 As you are using an iPad I again presume you own a Mac. 当您使用iPad时,我再次假定您拥有Mac。 Follow this tutorial: https://appletoolbox.com/2014/05/use-web-inspector-debug-mobile-safari/ as it is the only fool-proof method where you will find what was wrong. 请遵循此教程: https : //appletoolbox.com/2014/05/use-web-inspector-debug-mobile-safari/,因为它是唯一的防呆方法,可在其中发现问题所在。 Unfortunately, if you are using Windows machine then you would need to use Chrome and Android device. 不幸的是,如果您使用的是Windows计算机,则需要使用Chrome和Android设备。
  • There's also a chance, some of your *.js content is loading from localhost or other sources not available to your iPad. 还有一种可能,您的某些* .js内容是从localhost或iPad无法使用的其他来源加载的。 This also may be the case as you stated above alert is not triggering on iPad. 也可能是这种情况,因为您上面提到的警报未在iPad上触发。 Which would mean that some major JavaScript has occurred thus blocking the load of other JavaScript content. 这意味着已经出现了一些主要的JavaScript,从而阻止了其他JavaScript内容的加载。
  • And there's one other foolproof method you can use that always helped me in this case. 在这种情况下,您还可以使用另一种万无一失的方法来帮助我。 Trim your code to the bare minimum, even if that means you need to remove most of your HTML content and JavaScript. 将代码修剪到最低限度,即使这意味着您需要删除大部分HTML内容和JavaScript。 Test it, if it works, start including removed content. 对它进行测试(如果可行),开始包括已删除的内容。 First include remote JavaScript content, CSS and similar. 首先包括远程JavaScript内容,CSS等。 Then if it still works, start including actual HTML and code. 然后,如果仍然有效,请开始包含实际的HTML和代码。 Sooner or later you will stumble on the problematic code, missing content, or content that was not loaded into your iPad. 迟早您会偶然发现有问题的代码,缺少的内容或未加载到iPad的内容。

Thanks to all who provided some insight... 感谢所有提供了一些见解的人...

Turned out it was an external javascript file that contained a try/catch block as: 原来,这是一个外部的javascript文件,其中包含try / catch块,如下所示:

try {
   // code
}
catch {
   // code
}

When changed to: 更改为:

try {
   // code
}
catch(err) {
   // code
}

... after the change was made, all tests passed !! ...进行更改后,所有测试都通过了!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM