簡體   English   中英

向來自重定向URL的用戶顯示彈出消息

[英]Show pop-up message to users coming from redirected URLs

我想向301重定向域中的站點訪問者顯示彈出消息(我們稱其為previous.com)

這個想法是有幾個舊的URL:

  • previous.com/contact
  • previous.com/news
  • previous.com/test

並重定向到新的URL:

  • new.com/contact
  • new.com/news
  • new.com/test

要求是如果這些用戶通過重定向的URL來到網站,則向他們顯示彈出消息

JavaScript最好內置於此嗎?

<script language="JavaScript">

function checkRef() {
  if (document.referrer.indexOf('previous.com') > -1) {
    window.open('pop-up.html',"Link","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=450,left=30,top=80");

  }
  else  {

  }
}

</script>

這為我工作:

 function checkRef() { // Get the modal var modal = document.getElementById('myModal'); // Get the button that opens the modal var btn = document.getElementById("closeBtn"); // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; if (document.referrer.indexOf('previous.com') > -1) { modal.style.display = "block"; // When the user clicks on <span> (x), close the modal span.onclick = function() { modal.style.display = "none"; } // When the user clicks on the button, close the modal btn.onclick = function() { modal.style.display = "none"; } // When the user clicks anywhere outside of the modal, close it window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } } else { console.log('Not from previous.com'); } } 
 /* The Modal (background) */ .modal { display: none; /* Hidden by default */ position: fixed; /* Stay in place */ z-index: 1; /* Sit on top */ left: 0; top: 0; width: 100%; /* Full width */ height: 100%; /* Full height */ overflow: auto; /* Enable scroll if needed */ background-color: rgb(0,0,0); /* Fallback color */ background-color: rgba(0,0,0,0.4); /* Black w/ opacity */ } /* Modal Content/Box */ .modal-content { background-color: #fefefe; margin: 15% auto; /* 15% from the top and centered */ padding: 10px; border: 1px solid #888; width: 25%; /* Could be more or less, depending on screen size */ } .content {padding:8px; border:1px solid #cccccc; text-align: center;} .content h2 { font-size: 1rem; padding-left: 12%; padding-right: 12%; font-weight: normal;} .content p {padding-left: 15px; padding-right: 15px;} /* The Close Button */ .close { color: #333; float: right; font-size: 18px; font-weight: bold; background-color: #ccc; border: 1px solid #aaa; width: 20px; height: 20px; } .close:hover, .close:focus { color: black; text-decoration: none; cursor: pointer; } button { background-color: #5e8f40; color: #ffffff; padding: 15px; border: 0 none; padding-top: 10px; padding-bottom: 10px; padding-left: 30px; padding-right: 30px;} 
 <div id="myModal" class="modal"> <!-- Modal content --> <div class="modal-content"> <div class="content"> <span class="close">&times;</span> <p>Some text here...</p> <button id="closeBtn" onclick="setCookie('clicklink', 'yes', 30)">Close</button> </div> </div> </div> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM