Here's what I'm trying to do:
- Splash page on subdomain.domain1.com/splashpage.html
- User clicks a button and is redirected to subdomain.domain1.com/landingpage.html OR subdomain.domain2.com/landingpage.html
- Cookie set on subdomain.domain1.com/splashpage.html remembers their choice and automatically redirects them next time
I've successfully created the cookie using the jQuery cookies plugin and a very helpful outline here: Remember preferable language
The code I'm using to set the cookie:
<script type="text/javascript">
$(function () {
var url = 'domain1.com';
var east = 'subdomain.domain1.com/landingpage.html';
var west = 'subdomain.domain2.com/landingpage.html';
if ($.cookie('nameofmycookie') != null) {
if (window.location.href != url + '/' + $.cookie('nameofmycookie')) {
window.location.href = url + '/' + $.cookie('nameofmycookie');
}
}
$('#set-eastern').click(function () {
$.cookie('nameofmycookie', east, { expires: 999 });
alert('East was set as your choice');
});
$('#set-western').click(function () {
$.cookie('nameofmycookie', west, { expires: 999 });
alert('West was set as your choice');
});
});
</script>
A couple problems:
- My
east
andwest
variable URLs appear to be relative to theurl
variable, they're redirecting to domain1.com/subdomain.domain1.com/landingpage.html - On both of my /landingpage.html there is a base href which I cannot edit, so:
<base href="http://subdomain.domain1.com/landingpage.html" />
and<base href="http://subdomain.domain2.com/landingpage.html" />
Does anyone know what adjustments I need to make to the code in order to properly redirect users to the correct URL/domain?
Thanks so much.