这是一个可以做你想做的事的例子。
共有三个文件:index.html、ef.html 和 dh.html。只需将代码复制/粘贴到这三个文件中,它就可以完成您想要的操作。
请注意,页面上的大多数 javascript/jQuery 只是为了使示例正常工作。使页面重定向工作真正需要的唯一 jQuery 是:
<script type="text/javascript">
$(document).ready(function() {
fav_site = $.cookie('fav_website');
if (fav_site == 'ef') {
window.location.href ='ef.html';
}else if (fav_site == 'dh') {
window.location.href = 'dh.html';
}
}); //END $(document).ready()
</script>
索引.HTML
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="//cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js"></script>
<style>
</style>
<script type="text/javascript">
$(document).ready(function() {
fav_site = $.cookie('fav_website');
alert('Cookie Value is now: [' +fav_site+ ']');
if (fav_site == 'ef') {
window.location.href ='ef.html';
}else if (fav_site == 'dh') {
window.location.href = 'dh.html';
}
$('#mybutta').click(function() {
$.cookie('fav_website', 'ef', { path: '/', expires: 10 });
window.location.href = 'ef.html';
});
$('#mybuttb').click(function() {
$.cookie('fav_website', 'dh', { path: '/', expires: 10 });
window.location.href = 'dh.html';
});
}); //END $(document).ready()
</script>
</head>
<body>
<h1>MAIN PAGE (Index.html)</h1>
<input id="mybutta" type="button" value="GoTo Site EF">
<input id="mybuttb" type="button" value="Visit Site DH">
</body>
</html>
DH.HTML
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="//cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js"></script>
<style>
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#mybutt').click(function() {
$.cookie('fav_website', '', { path: '/', expires: 10 });
window.location.href = 'index.html';
});
$('#mybuttox').click(function() {
window.location.href = 'index.html';
});
}); //END $(document).ready()
</script>
</head>
<body>
<h1>Page DH DH DH DH DH DH DH DH DH DH</h1>
<input id="mybutt" type="button" value="Reset Cookies (Erase All)">
<input id="mybuttox" type="button" value="Return to Main Page">
</body>
</html>
EF.HTML
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css" />
<script src="//cdn.jsdelivr.net/jquery.cookie/1.3.1/jquery.cookie.js"></script>
<style>
</style>
<script type="text/javascript">
$(document).ready(function() {
$('#mybutt').click(function() {
$.cookie('fav_website', '', { path: '/', expires: 10 });
window.location.href = 'index.html';
});
$('#mybuttox').click(function() {
window.location.href = 'index.html';
});
}); //END $(document).ready()
</script>
</head>
<body>
<h1>Page EF</h1>
<input id="mybutt" type="button" value="Reset Cookies (Erase All)">
<input id="mybuttox" type="button" value="Return to Main Page">
</body>
</html>