javascript - 移动网站 anchor 链接不起作用

标签 javascript jquery html css jquery-mobile

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

关闭 7 年前

我的移动网站某些页面上的 anchor 链接有问题(索引页面工作正常),并且我进行了暂时有效的更改(将“http://example.com”更改为“http” ://www.example.com' ),但在 30 分钟内链接不再有效。我已经和非常(无用)有用的 Godaddy 交谈过,他们似乎无法帮助我,因为他们不处理“编码”问题......在这件事上任何帮助将不胜感激。网址:http://www.removalcompare.com/mobile/site/test/index.html (导航在页脚上,索引有效,但大多数其他页面没有)。

最佳答案

Here is a working fix

You can download the edited files here

问题 1

我看到您使用 WinHTTrack 复制了一个网站。不幸的是,该软件对站点的链接造成了一些困惑。如果您查看控制台,我们会看到显示的几个错误。

具体来说,WinHTTrack 将所有无模式 url ( //code.jquery.com/jquery-1.8.1.min.js ) 转换为您需要更正的相对 url ( ../../code.jquery.com/jquery-1.8.1.min.js )

我只会做它们 https://code.jquery.com/jquery-1.8.1.min.js


修复所有这些问题,当您单击任何链接时,您将开始看到错误消息“页面加载错误”。所以,我们还没有完成。

让我们看看how links work in jQuery Moblie :

To enable animated page transitions, all links that point to an external page (ex. products.html) will be loaded via AJAX. To do this unobtrusively, the framework parses the link's href to formulate an AJAX request (Hijax) and displays the loading spinner. All this is done automatically by jQuery Mobile.

If the AJAX request is successful, the new page content is added to the DOM, all mobile widgets are auto-initialized, then the new page is animated into view with a page transition.

If the AJAX request fails, the framework will display a small error message overlay (styled in the "e" swatch) that disappears after a brief time so this doesn't break the navigation flow. View an example of the error message.


问题2

此外,WinHTTrack 无法找到文件 js/calc.js在您从中复制站点的服务器上。默认情况下,发生这种情况时,WinHTTrack 会生成一个 html 页面作为丢失文件的占位符,并改为链接到它

因此,在这种情况下,WinHTTrack 生成了 <script src="js/calc.js"></script>进入<script src="js/calc.html"></script>这也导致了问题。

回顾how links work in jQuery Moblie :

Note: You cannot link to a multipage document with AJAX navigation active because the framework will only load the first page it finds, not the full set of internal pages. In these cases, you must link without AJAX (see next section) for a full page refresh to prevent potential hash collisions. There is currently a subpage plugin that makes it possible to load in multi-page documents.

我的猜测是包含 <script src="js/calc.html"></script>使页面成为所有“多页文档”,当您单击任何链接时,这会导致 ajax 请求失败。对于发生这种情况的具体原因,我可能是错误的,但是,解决此问题会使您的链接正常工作。

解决这个问题:

  • 如果你需要js/calc.js ,找到它的副本并将其添加到您的文件夹,然后将所有链接更改为 <script src="js/calc.js"></script>

  • 如果你不需要js/calc.js只需删除所有 <script src="js/calc.html"></script>所有文件的链接

关于javascript - 移动网站 anchor 链接不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31895956/

上一篇:javascript - JS Animate 的两个属性(!JQ)

下一篇:html - 下拉菜单打开时样式选择标签

相关文章:

javascript - Chrome 57+ 上的 RichFaces 应用程序出现 JS 错误 "Cannot read property ' switchToItem' 未定义”

javascript - 使用 angularjs 时轮播不工作?

php - 如何正确格式化帖子请求的正文?

javascript - 将对象与 jQuery 选择器一起使用

javascript - Bootstrap : calendar invoked in a popup is in background

html - 理解 CSS 定位 <p> & <h1>

javascript - AngularJS $q 与 socket.io 的 promise

javascript - 使用 queue() 加载多个文件并分配给全局变量

javascript - 单击按钮后如何关闭弹出模式

css - html 视频不会在谷歌浏览器上播放,但会在 firefox 上播放但不同