原生js中jsonp跨域实现调用必应每日壁纸API

Tips: 注意jsonp跨域需要后台支持。

必应壁纸接口: https://github.com/xCss/bing

1
2
3
4
5
6
7
8
9
10
11
function setBingImage(){
let script = document.createElement('script');
bing = {
bg: function (data) {
body.style.backgroundImage = `url('${data.data.url}')`;
}
}
script.src = `https://bing.ioliu.cn/v1/?d=0&w=1920&h=1080&callback=callback`
document.querySelector("head").appendChild(script);
document.querySelector("head").removeChild(script);
}