簡體   English   中英

如何在移動設備上包含外部JavaScript

[英]How to include external javascript on mobile devices

我有一個javascript廣告代碼,只想在600px及以下的設備上展示。 對於更大的屏幕,我有一個iframe廣告。 我讀了很多書,找不到類似的例子。

這是我需要較小屏幕的JavaScript

<script type="text/javascript">
ad_idzone = "39483984";
ad_width = "300";
ad_height = "100";
</script>
<script type="text/javascript" src="https://ads.exoclick.com/ads.js"></script>
<noscript><a href="http://main.exoclick.com/img-click.php?idzone=39483984" target="_blank"><img src="https://syndication.exoclick.com/ads-iframe-display.php?idzone=39483984&output=img&type=300x100" width="300" height="100"></a></noscript>

我已經讀過各種類型的方法,但是顯然行不通,我也不是很有經驗。 有什么建議么?

<script type="text/javascript">

if (screen.width<500){ 
//if screen width less than 500px it's probably a mobile device 
// so do this code... 

}
else{
// screen wider than 500 pixels 
// then do this code
} 
</script>

您可以嘗試使用javascript在較小的屏幕上附加廣告的javascript文件。

<script>
 if (screen.width < 500) {

   var myScript = document.createElement('script');
   myScript.setAttribute('type', 'text/javascript');
   myScript.setAttribute('src', 'https://ads.exoclick.com/ads.js');

   document.getElementsByTagName('head').item(0).appendChild(myScript);
 } else {
   showMyIframeAd();
 }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM