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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀