user4120314
user4120314

Reputation:

send same values to another variable?

I have to form pages and I am trying to send same values to another variable (linkmobile) if user agent is mobile. Could you please tell me what is the best way with minimal coding?

  var link = "reservation.html?";
  var linkmobile = "reservation-mobile.html?";

  link += "checkinYear="+ checkinYear;
  link += "&checkinDay="+ checkinDay;
  link += "&checkinMonth="+ checkinMonth;

  if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent)) {
    window.location.href = link-mobile;
  }
  else
    window.location.href = link;

}

Upvotes: 0

Views: 39

Answers (1)

TheVillageIdiot
TheVillageIdiot

Reputation: 40527

Try this:

    var link = "reservation.html?";  

    if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|OperaMini/i.test(navigator.userAgent)) {
        link = "reservation-mobile.html?";
    }

    link += "checkinYear="+ checkinYear;
    link += "&checkinDay="+ checkinDay;
    link += "&checkinMonth="+ checkinMonth;

    window.location.href = link;
}

Upvotes: 3

Related Questions