你好我正在尝试为我的网站开发facebook开放图形系统,我差不多完成了......
它需要发布当前页面url来运行动作..我使用document.url获取当前页面url到一个名为BASE的java脚本变量,但我不知道如何将它放在javascript中,因为它始终显示当我查看页面源代码时,url的变量名称intead ...
var base = document.URL;
function postCook()
{
FB.api(
'/me/video.watches',
'post',
{ video: CURRENT PAGE URL SHOULD BE HERE},
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
}
答案 0 :(得分:1)
当您查看页面源时,您会看到从服务器发送的代码。只需将变量放在那里就可以了。
var myURL = document.URL;
FB.api(
'/me/video.watches',
'post',
{ video: myURL },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
或
FB.api(
'/me/video.watches',
'post',
{ video: window.location.href },
function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});
答案 1 :(得分:1)
我在我的应用中使用它:
FB.api('/me/namespace:action&object='+encodeURIComponent(location.href),'post', function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Cook was successful! Action ID: ' + response.id);
}
});