简体   繁体   English

如何使我的广告适合车身宽度

[英]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.

相关问题 如何使我的 canvas 区域适合 iphone 浏览器? - How can i make my canvas area fit to the iphone browser? 使用“重复无”,如何使页脚背景适合100%的宽度 - With Repeat None, how can i make footer background to fit 100% width 如何使用内部宽度按比例缩放我的网页以适应任何显示尺寸? - How can I scale my webpage proportionally using inner width to fit any display size? 如何使HTML列的宽度可调? - How can I make an my HTML columns adjustable width? jQuery-调整大小 <body> 到页面宽度。 (缩放有效,我又如何使其缩小?) - jQuery - Resize <body> to page width. (zoom works, how can I make it shrink too?) 如何测量符合文档宽度的字符数? - How can I measure how many characters will fit the width of the document? 如何自动调整此HTML菜单的大小以适合父级宽度? - How can I auto size this HTML Menu to fit parent width? 如何让我的<h5>垂直适合父div? - How can I make my <h5> fit vertically into a parent div? 如何让我的移动菜单中的社交链接排成一行? - How can I make the social links in my mobile menu fit together on one line? 如何设置图像的高度和宽度,使其适合我在 fabric.js 中的 canvas 的大小? - How do I set both height and width of image so that it can fit the size of my canvas in fabric.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM