展示横幅广告
[!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>