Detect load type in jQuery: ajax vs regular http

Detect load type in jQuery: ajax vs regular http

Is there a way of knowing if a jQuery mobile page has been loaded directly (regular http call) or though ajax in order to load Adsense?

Basically, Google Adsense cannot be loaded in pages that are loaded via ajax because it throws the error message:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

So the solution is to only display the Google Adsense banner if it is a regular http request. For that, I'm using this method:

  1. var banner = false;
  2. $(document).on('mobileinit', function(){
  3. banner = true;
  4. });
Of course, there is no way to actually use that "banner" flag with this kind of Adsense code:

  1. <script type="text/javascript">
  2. google_ad_client = "ca-pub-XXXXXXXXXXXXXX";
  3. google_ad_slot = "XXXXXXXX";
  4. google_ad_width = 320;
  5. google_ad_height = 100;
  6. </script>
  7. <script type="text/javascript" src="//"></script>
and neither with the async method:
  1. <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-XXXXXXXXXXXX" data-ad-slot="XXXXXXX" data-ad-format="auto"></ins>
  2. <script>
  3. (adsbygoogle = window.adsbygoogle || []).push({});
  4. </script>
Any ideas? Thanks!