[英]How can i make my ads fit into body width
I have installed ads on my website recently and everything works fine in desktop version. 我最近在自己的网站上安装了广告,并且在桌面版中一切正常。 I want to change the ads basing on the screen weight, i have ads code like : 我想根据屏幕重量更改广告,我的广告代码如下:
<script type="text/javascript>
<script src="file.js">
<iframe>AD CODE </iframe>
</script>
I want to dynamicly change ads from desktop to mobile code basing on screen width using javascript but the problem is when i try to insert code into the ad zone the script 'js' inside will not run and the ad doesnt show. 我想使用javascript根据屏幕宽度动态地将广告从桌面代码更改为移动代码,但是问题是当我尝试将代码插入广告区域时,脚本“ js”将无法运行并且广告不会展示。
What is the best practice to do so ? 最佳做法是什么?
Thanks to all of you 感谢大家
It depends if you want the users screen width or width of the window. 这取决于您是否希望用户使用屏幕宽度或窗口宽度。 If you're trying to determine if the user is using a mobile phone then screen width would likely be most suitable. 如果您要确定用户是否正在使用手机,则屏幕宽度可能最合适。
var width = window.screen.availWidth;
if(width < 400){
//do mobile relevant action
} else {
//do desktop relevant action
};
This question has been answered very thoroughly here: Get the size of the screen, current web page and browser window 此问题已在此处得到非常彻底的解答: 获取屏幕的大小,当前网页和浏览器窗口的大小
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.