在下一次访问时记住用户选择以及重定向或隐藏模态框

发布于 2025-02-11 09:32:58 字数 3061 浏览 0 评论 0原文

我想创建一个模态框,以提示访问者在A或B之间进行选择。如果用户选择A,则会将其重定向到另一页,如果B,则它们会留在当前网站上,但是模态框消失了到内容。

我还需要一个选项来“记住我”,如果检查了,这将记住他们的个人资料,如果没有,将再次提示他们在A和B中进行选择。这是我到目前为止所拥有的。

重定向零件有效,但我无法使模态起作用。

<div id="boxes">
  <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> Please identity yourself
    <div id="lorem" style="text-align:center">
      <FORM NAME="form1">
        <select onchange="formChanged(this);" NAME="user" SIZE="1">
          <OPTION VALUE="non-value">Please make a selection
          <OPTION VALUE="https://redirection.com">PI
          <OPTION VALUE="fa">FA
        </select>
        <br>
        <input type="checkbox" id="remember" checked />Remember me
      </FORM>
    </div>
  </div>
  <div style="width: 1478px; font-size: 32pt; color:white; height: 602px; display: none; opacity: 0.8;" id="mask"></div>
</div>
setStatus = document.getElementById('remember');
setStatus.onclick = function() {
  if (document.getElementById('remember').checked) {
    localStorage.setItem('remember', "true");
  } else {
    localStorage.setItem('remember', "false");
  }
}

getStstus = localStorage.getItem('remember');
if (getStstus == 'true') {
  document.getElementById('remember').checked = true;
}

//  localStorage.clear();
if (localStorage && localStorage.user && remember.checked) {
  location = localStorage.user;
}

function formChanged(form) {
  var val = form.options[form.selectedIndex].value;
  if (val !== 'non-value' && val !== 'fa') {
    if (localStorage) {
      localStorage.user = val;
    }
    location = val;
  }

  var val = form.options[form.selectedIndex].value;
  if (val == 'fa') {
    if (localStorage) {
      localStorage.user = val;
    }
    $('.window').hide();
    $('#mask').hide();
  }
}

$(document).ready(function(){

    var id = '#dialog';

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    
    //transition effect     
    $('#mask').fadeIn(500); 
    $('#mask').fadeTo("slow",0.9);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
          
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(2000);     

//if close button is clicked
$('.window .close').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();
    
    $('#mask').hide();
    $('.window').hide();
});     

//if mask is clicked
//$('#mask').click(function () {
//  $(this).hide();
//  $('.window').hide();
//});       

});

I want to create a modal box that prompts visitors to choose between A or B. If user chooses A, they will be redirected to another page, and if B, then they stay on the current website, but the modal box dissapears giving them access to the contents.

I also need an option to "remember me", and if checked, this will remember their profile and if not, they will be prompted again to make a selection betweeen A and B. Here is what I have so far.

The redirection part works, but I cannot get the modal to work.

<div id="boxes">
  <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window"> Please identity yourself
    <div id="lorem" style="text-align:center">
      <FORM NAME="form1">
        <select onchange="formChanged(this);" NAME="user" SIZE="1">
          <OPTION VALUE="non-value">Please make a selection
          <OPTION VALUE="https://redirection.com">PI
          <OPTION VALUE="fa">FA
        </select>
        <br>
        <input type="checkbox" id="remember" checked />Remember me
      </FORM>
    </div>
  </div>
  <div style="width: 1478px; font-size: 32pt; color:white; height: 602px; display: none; opacity: 0.8;" id="mask"></div>
</div>
setStatus = document.getElementById('remember');
setStatus.onclick = function() {
  if (document.getElementById('remember').checked) {
    localStorage.setItem('remember', "true");
  } else {
    localStorage.setItem('remember', "false");
  }
}

getStstus = localStorage.getItem('remember');
if (getStstus == 'true') {
  document.getElementById('remember').checked = true;
}

//  localStorage.clear();
if (localStorage && localStorage.user && remember.checked) {
  location = localStorage.user;
}

function formChanged(form) {
  var val = form.options[form.selectedIndex].value;
  if (val !== 'non-value' && val !== 'fa') {
    if (localStorage) {
      localStorage.user = val;
    }
    location = val;
  }

  var val = form.options[form.selectedIndex].value;
  if (val == 'fa') {
    if (localStorage) {
      localStorage.user = val;
    }
    $('.window').hide();
    $('#mask').hide();
  }
}

$(document).ready(function() {

    var id = '#dialog';

    //Get the screen height and width
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

    //Set heigth and width to mask to fill up the whole screen
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    
    //transition effect     
    $('#mask').fadeIn(500); 
    $('#mask').fadeTo("slow",0.9);  

    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
          
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(2000);     

//if close button is clicked
$('.window .close').click(function (e) {
    //Cancel the link behavior
    e.preventDefault();
    
    $('#mask').hide();
    $('.window').hide();
});     

//if mask is clicked
//$('#mask').click(function () {
//  $(this).hide();
//  $('.window').hide();
//});       

});

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文