doushi4633 2016-07-11 05:23
浏览 40
已采纳

在移动设备上打开网站时弹出(php-javascript)弹出窗口

How can I make popup ads work only one time for mobile ios browser.

I am using (popup show every time : how I can make it show only first time)

<script type="text/javascript">
if( /iPad|iPhone/i.test(navigator.userAgent) ) {
var url=confirm("Would you like to download our mobile application?");
if (url==true)
{
var url = window.location.href = 'http://itunes.apple.com/us/app/AppId';
url.show(); 
   }
else
{
    }
}
</script>
  • 写回答

2条回答 默认 最新

  • dsyak22488 2016-07-11 05:34
    关注

    You should use cookies to store a value that the popup has been shown then add check to your popup that if the cookie exists then don't display the popup. I updated your code to reflect the changes you need to make, goodluck :)

      <script type="text/javascript">
        if( /iPad|iPhone/i.test(navigator.userAgent) ) {
    
            //cookie name mypopup not found so display the popup
           if(!getCookie("mypopup")){
                setCookie("mypopup",true); //sets the cookie mypopup
                var url=confirm("Would you like to download our mobile application?");
                if (url==true)
                {
                    var url = window.location.href = 'http://itunes.apple.com/us/app/AppId';
                    url.show(); 
                }else{
    
    
                }
           }
    
        }
    
    //function to retrieve cookie value
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i = 0; i <ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0)==' ') {
                c = c.substring(1);
            }
            if (c.indexOf(name) == 0) {
                return c.substring(name.length,c.length);
            }
        }
        return "";
    }
    
    //function to set the cookie
    function setCookie(cname, cvalue) {
        document.cookie = cname + "=" + cvalue + "; ";
    }
        </script>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试