0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【monaca】nend広告をタップできない(何も起こらない)時の解決方法

Posted at

monacaアプリにnend広告を実装しても、広告はちゃんと表示できるのに広告をタップしても何も反応しないことがあります。原因は、広告のロードにタイムラグがあるからです。タイムラグがあったらなぜ反応しないのかは僕の知識ではよくわかりませんが、とにかく原因はそれです。

解決方法を探していたら次の記事を見つけ、これで解決することができました。

ただ、この記事は2015年に書かれたもので、このままではちゃんと動かないので少し修正を加えて以下のようにしました。これをheadに挿入すると広告をタップできるようになります。


         addEventListener('load', onLoad, false);
      function onLoad() {
                //nendの広告タグのロードにラグがあるので、決め打ちで処理を遅延させています。
                var TIME_FOR_WAITING_NEND_AD = 500;
    
                setTimeout(function () {
    
                    var nendAdSpace = document.querySelector('div[id^=nend_adspace]');
                    var nendAdAnchors = nendAdSpace.querySelectorAll('a');
    
                    for (var i = 0; i < nendAdAnchors.length; i++) {
                        var hrefShelter = nendAdAnchors[i].href;
                        nendAdAnchors[i].removeAttribute('href');
                        nendAdAnchors[i].addEventListener('click', function () {
                           cordova.InAppBrowser.open(hrefShelter, "_system", 'location=yes');
                        }, false);
                    }                
    
                }, TIME_FOR_WAITING_NEND_AD);
            }

cordova.InAppBrowser.open(hrefShelter, "_system", 'location=yes');によって広告がSafariで開くようになっています。InAppBrowserプラグインを有効にしておいてください。

ちょこっと宣伝

monacaでアプリ作ってます

オナ禁アプリ↓
kinyoku-100px-icon.png
禁欲エボリューション

レポート用メモアプリ↓
mem-100px-icon.png
文字数制限メモ

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?