javascript - 如何在页面加载前禁用 jQuery Mobile 中的 Ajax?

标签 javascript jquery html ajax jquery-mobile

在我的移动网站上。我一直在尝试加载 Adsense 移动广告,但在页面自行加载后它们继续占据整个页面。

我确实发现,如果我禁用 ajax,页面将与广告一起正常加载。这仅适用于我加载的第二页,因为我单击带有标签的链接...

data-ajax="false"

这使得下一页完美加载。

问题:加载的第一个页面将被 adsense 广告覆盖,因为启用了 ajax(我认为)。

基本上我的页面的第一部分是这样的......

<html>
<head>

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc3/jquery.mobile-1.0rc3.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script src="http://code.jquery.com/mobile/1.0rc3/jquery.mobile-1.0rc3.min.js"></script>
<script language="text/javascript">

      $(document).bind("mobileinit", function () {

            $.mobile.ajaxEnabled = false;

      });

</script>
</head>
<body>

    <div data-role="header">
        <h1>Angry Birds Cheats</h1>
    </div>



    <div data-role="content">

<div>
    <script type="text/javascript"><!--
  // XHTML should not attempt to parse these strings, declare them CDATA.
  /* <![CDATA[ */
  window.googleAfmcRequest = {
    client: '',
    format: '',
    output: '',
    slotname: '',
  };
  /* ]]> */
//--></script>
<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script>
</div>

我确实尝试在代码中禁用ajax,但我不认为这是因为广告仍然占据了整个页面......

我在想,也许我可以让访问者从某个页面开始,然后将他们重定向到一个非 ajax 的页面。

最佳答案

查看文档以绑定(bind)到 mobileinit 事件:http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html

特别是这一点:

Because the mobileinit event is triggered immediately upon execution, you'll need to bind your event handler before jQuery Mobile is loaded.

以下是绑定(bind)到 mobileinit 事件的正确格式:

<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc3/jquery.mobile-1.0rc3.min.css" />
<script src="http://code.jquery.com/jquery-1.6.4.min.js"></script>
<script type="text/javascript">
$(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
});
</script>
<script src="http://code.jquery.com/mobile/1.0rc3/jquery.mobile-1.0rc3.min.js"></script>

首先是 jQuery Core(所以 .bind() 将可用),然后是 mobileinit 事件处理程序,然后是 jQuery Mobile js 文件(这是最后一个,所以mobileinit 的事件处理程序将在事件触发之前设置)。

您可以通过在函数中放置一个 alert 来测试您当前的 mobileinit 事件处理程序是否触发。

关于javascript - 如何在页面加载前禁用 jQuery Mobile 中的 Ajax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8684234/

相关文章:

javascript - XMLHttpRequest 响应类型和 JSON

javascript - 隐藏主要对象/类 javascript

javascript - 当我运行 animate 函数时没有任何反应,我能做些什么来解决这个问题?

javascript - 返回插入的子文档

php - 使用分页按类别列出项目

javascript - 为什么我的按钮没有打印出代码并选择正确的选项?

javascript - JWplayer 7 - 将事件类添加到当前播放的视频

javascript - jQuery Submit 函数不会发布值

jquery - 实现图钉滚动跳转

html - CSS有图像的div穿过并滚动