如何在页面加载前禁用 jQuery Mobile 中的 Ajax? [英] How To Disable Ajax In jQuery Mobile Before Page Load?
问题描述
在我的移动网站上.我一直在尝试加载 Adsense 移动广告,但在页面自行加载后,它们继续占据整个页面.
我确实发现如果我禁用 ajax,页面会与广告一起加载得很好.这仅适用于我加载的第二页,因为我单击了带有标签的链接...
data-ajax="false"
这使得下一页完美加载.
问题:加载的第一页将被 Adsense 广告覆盖,因为启用了 ajax(我认为).
基本上我的页面的第一部分看起来像这样...
<头><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><脚本语言="text/javascript">$(document).bind("mobileinit", function () {$.mobile.ajaxEnabled = false;});头部><身体><div data-role="header"><h1>愤怒的小鸟秘籍</h1>
<div data-role="内容"><div><script type="text/javascript"><!--//XHTML 不应尝试解析这些字符串,将它们声明为 CDATA./* <![CDATA[ */window.googleAfmcRequest = {客户: '',格式: '',输出: '',插槽名称:'',};/* ]]>*///--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_afmc_ads.js"></script>
我确实尝试在代码中禁用ajax,但我认为不是因为广告仍然占据了整个页面...
我在想,也许我可以在某个页面启动访问者并将他们重定向到非 ajax 的页面.
查看文档以绑定到 mobileinit
事件:http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html
特别是这一点:
<块引用>因为mobileinit事件一执行就立即触发,您需要在加载 jQuery Mobile 之前绑定您的事件处理程序.
以下是绑定到 mobileinit
事件的正确格式:
<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 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
事件处理程序是否未触发.
On my mobile website. I've been trying to load Adsense Mobile ads, but they continue to take up the entire page after the page loads itself.
I did figure out that if I disable ajax the page would load fine with the ad together. This only works on the second page I load because I click a link with the tag...
data-ajax="false"
Which makes the next page load perfectly.
Problem: The first page loaded will be overwritten by the adsense ad because ajax is enabled (I think).
Basically the first part of my page looks like this...
<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>
I did try to disable ajax in the code, but I don't think it is because the ad still takes up the entire page...
I was thinking that maybe I could start the visitor at a certain page and redirect them to a page that is non-ajax.
Check-out the docs for binding to the mobileinit
event: http://jquerymobile.com/demos/1.0/docs/api/globalconfig.html
Specifically this bit:
Because the mobileinit event is triggered immediately upon execution, you'll need to bind your event handler before jQuery Mobile is loaded.
Here is the proper format for binding to the mobileinit
event:
<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>
First the jQuery Core (so .bind()
will be available), then the mobileinit
event handler, then the jQuery Mobile js file (this is last so the event handler for mobileinit
will be set before the event is fired).
You can test that your current mobileinit
event handler is not firing by putting an alert
in the function.
这篇关于如何在页面加载前禁用 jQuery Mobile 中的 Ajax?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!