sunnycupertino / cordova-plugin-admob-simple

Cordova plugin allowing Admob interstitials and banner ads.
MIT License
164 stars 150 forks source link

Jquery question #26

Closed yanbaha closed 6 years ago

yanbaha commented 6 years ago

When I link the index page to Jquery (necessary for the menu) Admob does not show. When I remove the Jquery Admob is working again but menu does not. is there any solution? is there another way to add a dropdown menu linked to tabs without Jquery? thank you

sunnycupertino commented 6 years ago

Not sure on that one. It's really hard to debug this kind of thing without having the whole project here in front of us, and we don't provide that level of support anyway. The ads do work well with jquery tabs, so I'm not sure what your problem is.

yanbaha commented 6 years ago

here are the codes if anyone can help, I have spent many weeks trying to fix this problem:

index html with jquery inserted in head part of the page:

`<!DOCTYPE html>

****

` java code for menu: `$(document).ready(function(){ (function($) { $('#header__icon').click(function(e){ e.preventDefault(); $('body').toggleClass('with--sidebar'); }); $('#site-cache').click(function(e){ $('body').removeClass('with--sidebar'); }); })(jQuery); }); $(document).ready(function () { $(".tab-content").hide(); $(".tab-content:first").show(); $(".menu li:first").addClass("active"); $(".menu a").click(function(){ $(".menu li").removeClass("active"); $(this).parent().addClass("active"); var currentTab = $(this).attr("href"); $(".tab-content").hide(); $(currentTab).show(); $('body').removeClass('with--sidebar'); return false; }); }); $('a').click(function() { if (this.host !== window.location.host) { window.open(this.href, '_system'); return false; } }); ` index.js where Admob code is added: `/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ var app = { // Application Constructor initialize: function() { document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); }, // deviceready Event Handler // // Bind any cordova events here. Common events are: // 'pause', 'resume', etc. onDeviceReady: function() { this.receivedEvent('deviceready'); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); initAd(); showBannerFunc(); showInterstitialFunc(); console.log('Received Event: ' + id); } }; //initialize the goodies function initAd(){ if ( window.plugins && window.plugins.AdMob ) { var ad_units = { ios : { banner: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx', //PUT ADMOB ADCODE HERE interstitial: 'ca-app-pub-xxxxxxxxxxx/xxxxxxxxxxx' //PUT ADMOB ADCODE HERE }, android : { banner: 'ca-app-pub-1266469958489664/7154583482', //PUT ADMOB ADCODE HERE interstitial: 'ca-app-pub-1266469958489664/6066458015' //PUT ADMOB ADCODE HERE } }; var admobid = ( /(android)/i.test(navigator.userAgent) ) ? ad_units.android : ad_units.ios; window.plugins.AdMob.setOptions( { publisherId: admobid.banner, interstitialAdId: admobid.interstitial, adSize: window.plugins.AdMob.AD_SIZE.SMART_BANNER, //use SMART_BANNER, BANNER, LARGE_BANNER, IAB_MRECT, IAB_BANNER, IAB_LEADERBOARD bannerAtTop: false, // set to true, to put banner at top overlap: true, // banner will overlap webview offsetTopBar: false, // set to true to avoid ios7 status bar overlap isTesting: false, // receiving test ad autoShow: true // auto show interstitial ad when loaded }); registerAdEvents(); } else { //alert( 'admob plugin not ready' ); } } //functions to allow you to know when ads are shown, etc. function registerAdEvents() { document.addEventListener('onReceiveAd', function(){}); document.addEventListener('onFailedToReceiveAd', function(data){}); document.addEventListener('onPresentAd', function(){}); document.addEventListener('onDismissAd', function(){ }); document.addEventListener('onLeaveToAd', function(){ }); document.addEventListener('onReceiveInterstitialAd', function(){ }); document.addEventListener('onPresentInterstitialAd', function(){ }); document.addEventListener('onDismissInterstitialAd', function(){ }); } //display the banner function showBannerFunc(){ window.plugins.AdMob.createBannerView(); } //display the interstitial function showInterstitialFunc(){ window.plugins.AdMob.createInterstitialView(); //get the interstitials ready to be shown and show when it's loaded. window.plugins.AdMob.requestInterstitialAd(); } app.initialize();` As I mentioend above; If I remove jquery link Admob is working but menu does not. If I keep it Admob does not show.
sunnycupertino commented 6 years ago

Is this the correct location of the jquery file src="jquery-1.9.js"?

I mean is it really in the same folder as the index html file?

Also I would try adding the jquery file lower down the page, maybe after calling the cordova.js. Play around with it as the order things get called matters.

yanbaha commented 6 years ago

Yes it is in the same folder with index html. O was making tests so I didn’t put it in the JS folder. I will give it a try and see.

yanbaha commented 6 years ago

I have finally fixed the problem. I didn't pay attention to this part of the code: var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received');

I have removed thses default classes from index.html and this disabled the index.js to load. Thank you for your time

sunnycupertino commented 6 years ago

Glad you solved it.