You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cordova Admob Free插件无法显示广告问题求助

Troubleshooting Your Cordova Admob Free Plugin Issues

Let's break down the problems you're facing and fix them one by one:

1. Fix Critical Code Errors First

Your current code has several typos and syntax mistakes that are causing immediate failures:

  • Incorrect script tag: You wrote <script src="text/javascript"> instead of <script type="text/javascript">. This is why you're seeing the MIME type mismatch error in the browser—your app is trying to load a non-existent file named text/javascript.
  • Spelling mistake: addEventListerner → should be addEventListener (missing an "e")
  • Spelling mistake: insterstitial → correct spelling is interstitial (you have this error in both the button ID and function code)
  • Incorrect banner ad setup: You're passing the ad ID to banner.show() instead of configuring it in banner.prepare().

Here's your corrected code:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="css/index.css">
<title>Cordova Admob Free</title>
</head>
<body>
<div>
<button id="interstitialad" >Show Interstitial Ad</button>
</div>
<script src="js/cordova.js"></script>
<script type="text/javascript">
document.addEventListener('deviceready', function() {
    // Initialize and show banner ad
    admob.banner.prepare({
        id: 'ca-app-pub-3940256099942544/6300978111',
        autoShow: true
    });
}, false);

document.getElementById('interstitialad').addEventListener('click', showInterstitialAd);

function showInterstitialAd() {
    admob.interstitial.config({
        id: 'ca-app-pub-3940256099942544/1033173712'
    });
    admob.interstitial.prepare();
    // Add a listener to show the ad once it's loaded
    admob.interstitial.on('load', function() {
        admob.interstitial.show();
    });
}
</script>
</body>
</html>

2. Verify Plugin Setup

Make sure you've properly installed the plugin:

cordova plugin add cordova-plugin-admob-free --save

Also, confirm that your AndroidManifest.xml has the required permissions (the plugin should add these automatically, but it's worth checking):

  • android.permission.INTERNET
  • android.permission.ACCESS_NETWORK_STATE

3. How to Check Android Emulator Logs

To debug why ads aren't showing on the Android emulator, use these methods:

  • Using adb logcat: Open your terminal and run:
    adb logcat | grep -i admob
    
    This filters logs to show only Admob-related messages, which will tell you if there's an issue with ad loading (like network errors, invalid IDs, or initialization problems).
  • Android Studio Logcat: Open Android Studio, connect your emulator, and go to the Logcat tab at the bottom. Select your emulator and app from the dropdowns, then filter for keywords like "Admob" or "Ads" to see detailed error logs.

4. Important Note About Browser Testing

The cordova-plugin-admob-free does not support the browser platform. Testing with cordova run browser will never work for Admob ads—always test on an Android emulator or physical Android device.

内容的提问来源于stack exchange,提问作者paul mart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 23:47:30