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 oled显示有问题,初始化后应该啥也不显示,但却亮了一大片
    • ¥15 【通信原理】为什么传信率不变?频带利用率为啥没有二倍
    • ¥15 CANOPEN SDO
    • ¥15 r语言数据集循环获取问题
    • ¥30 求佬们帮助,总是出bug,求佬们解决一下bug
    • ¥15 后端Java转换字符串传给前端,前端如何解析呢?
    • ¥15 psychopy(python为基础的)中引入cmd
    • ¥15 不知道怎么去做关于前端电子请柬
    • ¥15 Ubuntu22.04打开是tty界面。提示OOM
    • ¥15 存储过程或函数中的结果集类型变量如何使用。