展示横幅广告
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.adview.showBannerAd(success, error,options)
支持平台:
- Android
- iOS
参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| success | Function | 是 | 成功回调函数 |
| error | Function | 是 | 失败回调函数 |
| options | Object | 否 | 参数对象 |
success函数没有返回,直接加载广告
error函数会返回一个字符串,错误的相关信息
options参数为一个对象,其属性包含以下一项或多项:
type(String/ 可选) --广告位置,可取值:top(顶部)、center(居中)、bottom(底部);默认值:top;(注意:以下 x、y在type基础上进行位置调整。例如:x取值30,type取值top,是在type是top的基础上向下平移30距离)x(Number/ 可选) -- 距离顶部的偏移量,基于type的值,默认值:0(请输入大于等于0的数),单位pxy(Number/ 可选) -- 距离底部的偏移量,基于type的值,默认值:0(请输入大于等于0的数),单位px
[!WARNING]
- 关于
type、x、y组合方式五种,选择其中一种传参:
- 1.
type;- 2.
type值为top和x;- 3.
type值为center和x;- 4.
type值为center和y;- 5.
type值为bottom和y;- 关于
type在值为top时,iOS位于状态栏下方;- 若
x和y都有值且都大于0,则取x值,y值为0。
示例代码
设置广告居上显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居上显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
});
}
</script>
设置广告居上向下偏移30显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居上向下偏移30显示
navigator.adview.showBannerAd(
function(success) {
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'x':30,'type':'top'});
}
</script>
设置广告居中显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居中显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'type':'center'});
}
</script>
设置广告居中向下偏移30显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居中向下偏移30显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'x':30,'type':'center'});
}
</script>
设置广告居中向上偏移30显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居中向上偏移30显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'y':30,'type':'center'});
}
</script>
设置广告居下显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居下显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'type':'bottom'});
}
</script>
设置广告居下向上偏移30显示
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
//设置广告居下向上偏移30显示
navigator.adview.showBannerAd(
function (success){
console.log(JSON.stringify(success));
},function (error){
alert(JSON.stringify(error));
},{'y':30,'type':'bottom'});
}
</script>