weixin_33698043 2018-09-14 03:53 采纳率: 0%
浏览 23

每次运行一次功能

Hi and thanks in advance of any support on this.

I have a site where I'm offering to send US visitors back to our US specific website via a Modal popup qwhen they land on our AU site.

I only want the script to run once per visit.

What would I need to add to below to achieve this?

Thanks (ps- very new to ajax and anything outside HTML / CSS)

$(document).ready(function() {

  $.ajax({
    url: 'https://api.ipstack.com/check?access_key=##hidden##',
    dataType: 'jsonp',
    success: function(location) {
      // AU -- Australia
      if (location.country_code === 'AU') {

      } else {
        // Reveal Modal to select AU or US store

        // Modal 1
        $('#popup-2').slickModals({
          popupType: 'delayed',
          delayTime: 0,
          overlayColor: 'rgba(0, 0, 0, 0.1)',
          popupWidth: '420px',
          popupHeight: 'auto',
          popupLocation: 'topCenter',
          popupAnimationDuration: '0.4',
          popupAnimationEffect: 'slideTop',
          popupMargin: '30px',
          popupPadding: '20px',
          mobileBreakPoint: '420px',
          mobileLocation: 'topCenter',
          mobileWidth: '100%',
          mobileHeight: 'auto',
          mobilePadding: '0px',
          reopenClass: 'openSlickModal-2'

        })
      }
    }
  });

});
  • 写回答

1条回答 默认 最新

  • weixin_33698043 2018-09-14 04:01
    关注

    Assuming a "visit" is any browser session which ends when the tab / browser is closed, you can use sessionStorage to store a flag.

    For example

    if (!sessionStorage.getItem('redirect-offered')) {
        $.ajax(...)
    }
    

    and in your success handler

    if (location.country_code === 'AU') {
    
    } else {
      // the value doesn't really matter, it just has to be "truthy"
      sessionStorage.setItem('redirect-offered', 1); 
    
      $('#popup-2').slickModals(...)
    }
    

    Full code example here ~ https://pastebin.com/X7Jy7BD2

    评论

报告相同问题?

悬赏问题

  • ¥15 数据库原理及应用上机练习题
  • ¥30 征集Python提取PDF文字属性的代码
  • ¥15 如何联系真正的开发者而非公司
  • ¥15 有偿求苍穹外卖环境配置
  • ¥15 代码在keil5里变成了这样怎么办啊,文件图像也变了,
  • ¥20 Ue4.26打包win64bit报错,如何解决?(语言-c++)
  • ¥15 clousx6整点报时指令怎么写
  • ¥30 远程帮我安装软件及库文件
  • ¥15 关于#自动化#的问题:如何通过电脑控制多相机同步拍照或摄影(相机或者摄影模组数量大于60),并将所有采集的照片或视频以一定编码规则存放至规定电脑文件夹内
  • ¥20 深信服vpn-2050这台设备如何配置才能成功联网?