在我的移动网站上。我一直在尝试加载 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/