Wednesday, June 5, 2024
 Popular · Latest · Hot · Upcoming
144
rated 0 times [  145] [ 1]  / answers: 1 / hits: 53968  / 13 Years ago, fri, december 30, 2011, 12:00:00

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.


More From » jquery

 Answers
90

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.


[#88307] Thursday, December 29, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leighm

Total Points: 423
Total Questions: 101
Total Answers: 112

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;