现在,我在引荐来源网址的功能中具有以下重定向代码:

document.addEventListener('DOMContentLoaded', function() {
  console.log(isMobile);
  var referrer = document.referrer;
  if(referrer.indexOf('site1.com') !== -1 || referrer.indexOf('site2.com') !== -1) {

   if(isMobile.phone) {
      window.location = "http://www.landingphone.com";
      console.log('Is phone');
    } else if(isMobile.tablet) {
       window.location = "http://www.landingtablet.com";
       console.log('Is tablet');
     } else {
       window.location = "http://www.landingdesktop.com";
       console.log('Is desktop');
     }

   } else {
     window.location = "http://www.anotherlanding.com";
   }
 });


可以使用此代码在引用站点site1和site2.com中进行重定向,但是如果我需要将另一个引用站点(例如site3.com)重定向到另一个登录站点(例如www.landingphone2.com,landingtablet2.com和landingdesktop2)。 com)。我需要在代码中添加什么?我需要修改什么?

非常感谢你。

最佳答案

您可以尝试类似的方法,在答案中添加注释中提到的另一个else if语句。

document.addEventListener('DOMContentLoaded', function() {
  console.log(isMobile);
  var referrer = document.referrer;
  if (referrer.indexOf('site1.com') !== -1 || referrer.indexOf('site2.com') !== -1) {

   if (isMobile.phone) {
      window.location = "http://www.landingphone.com";
      console.log('Is phone');
    } else if (isMobile.tablet) {
       window.location = "http://www.landingtablet.com";
       console.log('Is tablet');
     } else {
       window.location = "http://www.landingdesktop.com";
       console.log('Is desktop');
     }

   } else if (referrer.indexOf('site3.com') !== -1) {

     // Do your other redirects here

   } else {
     window.location = "http://www.anotherlanding.com";
   }
 });

10-07 19:19
查看更多