mraid undefined

淺唱寂寞╮ 提交于 2019-12-11 01:30:19

问题


I've been trying to create an mraid compliant ad, but haven't gotten very far. According to the official documentation, which can be found at this link, the addition of a simple

<script src='mraid.js'></script>

should be sufficient. This, however, doesn't seem to be the case. I copied the following example code to test the existence of the mraid object, but it just stays undefined. The precise FireBug error is:

ReferenceError: mraid is not defined

I'm trying to execute the following (very simple) code:

if(mraid.getState() !='ready'){
console.log("MRAID NOT READY");}

Does anyone have any experience with this problem?


回答1:


Yes, it's not quite as simple as that, and the spec isn't entirely clear.

mraid.js is injected by whatever ad platform your being flighted from.

It looks something like this:

App -> Ad SDK -> MRAID Ad

The Ad SDK instantiates a UIWebView and injects mraid.js to be available. Then your script tag above finds it, loads it, and everything else resolves itself from there.

Your options are either:

  1. make your own mraid.js for testing purposes that has enough of the spec to be handy /testing
  2. spin up a mobile ad server SDK that does the above for you, and then just test against that
  3. checkout http://webtester.mraid.org which will let you avoid some of the above

2 is the most precise. 1 & 3 get you far, but nothing compares to the real thing in app with an actual ad server's sdk handling things.



来源:https://stackoverflow.com/questions/15432260/mraid-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!