function setCookie(){
if ( navigator.userAgent.indexOf('Safari') != -1 &&
navigator.userAgent.indexOf('Chrome') == -1 ){
window.open('safari.php','','width=200,height=100' );
}
}
// then we set the cookie in safari.php
来源:http://www.reizbombardement.de/archives/safari-5-1-4-enforces-cookie-policy
//2013 年 7 月 23 日更新
这种解决此问题的糟糕方法在 Safari 6 之前一直有效。
请参阅下面的@Fabio Antunes 和@ncubica cmets。
//2013 年 7 月 23 日更新,作者 Fabio Antunes
这是我的代码
在登录页面上,我们将有一个关于应用程序的简要说明和一个类似“进入”的按钮。我正在使用 jquery 来简化此过程,为单击事件创建一个侦听器,我将只放置 javascript 代码,因为我假设您已经拥有着陆页的其余 html 代码:
$(document).on("click", "#bt-landing", function(){
var left = (screen.width/2)-(500/2);
var top = (screen.height/2)-(250/2);
window.open('URL_FOR_THE_PHP_THAT_WILL_CREATE_THE_SESSION', '_blank', 'width=500,height=250,toolbar=0,location=0,menubar=0, top='+top+', left='+left);
});
这将打开一个小窗口,大小为 500 x 250 像素,以屏幕为中心。
小窗口的代码是这样的:
<?php setcookie("safari_cookie", "1");?>
<html>
<head>
<meta charset="utf-8">
<title>THE NAME OF YOUR APP OR SOMETHING THAT THE USER WE'LL READ AND ASSUME THAT THIS SMALL WINDOW IS RELIABLE</title>
</head>
<body>
<script type="text/javascript">
$(document).ready(function(){
setTimeout(function(){window.close()},1000);
})
</script>
</body>
</html