我有一个带有javascript的index.php文件的应用程序,当用户登录时,javascript加载存储在content.php中的页面内容
(k,我已经发现如果用户允许使用弹出窗口,它可以在safari中运行。我在firefox中遇到了同样的错误。那么弹出窗口会成为敌人吗?我怎样才能重写这个使用弹出窗口?)
的index.php:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>My app</title>
<link type="text/css" rel="stylesheet" href="css/style.css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script src="js/jquery.validationEngine.js"></script>
<script src="js/jquery.validationEngine-en.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
<script src="js/functions.js"></script>
</body>
</html>
functions.js:
FB.init({
appId : '123456789',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.login(function(response) {
if (response.session) {
if (response.perms) {
$.get("content.php", {get: "form"}, function(data){
$('body').append(data);
});
} else {
top.location.href="http://example.com";
}
} else {
top.location.href="http://www.example.com";
}
}, {perms:'publish_stream'});
它适用于Firefox和Internet Explorer,但在Chrome,Safari和Opera中却没有。 我在Chrome中使用javascript debug获得了此错误:
Unsafe JavaScript attempt to access frame with URL https://www.facebook.com/login.php?api_key=123456789&skip_api_login=1&display=popup&cancel_url=http%3A%2F%2Fstatic.ak.fbcdn.net%2Fconnect%2Fxd_proxy.php%3Fversion%3D0%23cb%3Df13bcfbe1%26origin%3Dhttp%253A%252F%252Fexample.com%252Ff1fd4b982c%26relation%3Dopener%26transport%3Dpostmessage%26frame%3Df206b2144c%26result%3D%2522xxRESULTTOKENxx%2522&fbconnect=0&next=https%3A%2F%2Fwww.facebook.com%2Fdialog%2Fpermissions.request%3F_path%3Dpermissions.request%26app_id%3D152123456789%26redirect_uri%3Dhttp%253A%252F%252Fstatic.ak.fbcdn.net%252Fconnect%252Fxd_proxy.php%253Fversion%253D0%2523cb%253Df13bcfbe1%2526origin%253Dhttp%25253A%25252F%25252Fexample.com%25252Ff1fd4b982c%2526relation%253Dopener%2526transport%253Dpostmessage%2526frame%253Df206b2144c%2526result%253D%252522xxRESULTTOKENxx%252522%26sdk%3Djoey%26display%3Dpopup%26api_key%3D123456789%26fbconnect%3D0%26locale%3Den_US%26method%3Dpermissions.request%26perms%3Dpublish_stream%26return_session%3D1%26session_version%3D3%26from_login%3D1&rcount=1 from frame with URL http://example.com/myfacebookapp/. Domains, protocols and ports must match.
在Opera中,它会卡在弹出窗口(允许弹出窗口)上,并带有以下URL:
http://static.ak.fbcdn.net/connect/xd_proxy.php?version=0#cb=f5132b51b60fbe&origin=http%3A%2F%2Fexample.com%2Ff10a57ba8d445c&relation=opener&transport=flash&frame=f19023256ffd8&result=%7B%22perms%22%3A%22publish_stream%22%2C%22selected_profiles%22%3A1245738876%2C%22session%22%3A%22%7B%5C%22session_key%5C%22%3A%5C%222.buXjHddfcr_xKQHVeu_FXw__.3600.1299679200-1245738876%5C%22%2C%5C%22uid%5C%22%3A%5C%221245738876%5C%22%2C%5C%22expires%5C%22%3A1299679200%2C%5C%22secret%5C%22%3A%5C%22glwIAcpeG0HDT__0z1QI3g__%5C%22%2C%5C%22access_token%5C%22%3A%5C%22152384968151443%7C2.buXjHdcfcr_xKQHVeu_FXw__.3600.1299679100-1245738876%7CdyZCE5trqgMkU0HSzSorX3jqbIs%5C%22%2C%5C%22sig%5C%22%3A%5C%228724dd80df9f16e7c3a2ce1b06f8d1e1%5C%22%7D%22%7D
所以我的问题是:我怎样才能让它在所有浏览器中运行(最好是Firefox,IE,Chrome和Safari)?
(编辑:我更改了网址并删除了代码和网址到我的应用)
答案 0 :(得分:0)
我也有类似的弹出窗口体验。最终,我从您正在使用的客户端流模型转移到服务器流模型,服务器在该模型中进行重定向。
(我从来没有通过Javascript来解决这个问题,但我在文档中看到的内容似乎没有关闭弹出窗口的选项。http://developers.facebook.com/docs/reference/javascript/fb.login/)
我不能为您提供一个php示例,因为我的东西是在.NET中,但我认为它应该以类似的方式为您工作:
没有弹出窗口,没有javascript。