如何在运行时更改fb-video的视频网址,让播放器重新加载视频而不刷新页面:
<div id="fb-root" style="height: auto"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-video"
data-href="https://www.facebook.com/abcxyz/videos/vb.123/123/?type=1"
data-allowfullscreen="true"></div>
这就是我现在在HTML中加载页面的代码。我现在只想知道是否有可能以某种方式更改数据-href,然后让Facebook嵌入式视频播放器指向新视频。
答案 0 :(得分:6)
在更改FB.XFBML.parse()
属性的值后调用JavaScript SDK的data-href
方法。
以下是一些文档:
http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/
我试图创建一个CodePen或JSBin示例,但Facebook的SDK脚本与沙盒iframe没有很好的协作(它尝试更改document.domain
,这是不允许的) ,所以什么都不会加载。不过,这种方法在我目前的项目中对我有用。
答案 1 :(得分:0)
{
"session_key": "5.zj24rk1iHCRNQw.1602142801.26-100055829688425",
"uid": 100055829688425,
"secret": "9d6082e678f882fa59131bb90425ed03",
"access_token": "EAAAAAYsX7TsBACy8MNjCjeFlxoLUfHAetnLNUEFCHjiRdyJoL6Td9LaM6J7sUfvCWDrugNUKt68DQ0kZAzSHoXDA0ZCZB1ePVZBAWNY7r7HQe5ZApXWCxqPpuJ9fgUgnHjcZCTUVhkBBdExuYsDQI7DWXJGfgsIE2JDPYZCDdZBCjR1Cn6Sg5bd1IkHlZBwDey5LEGO50weSYD9yp9XI7xEuKVIGjAXhDlAsZD",
"machine_id": "UcJ-X0qUMXyP0GIAuWWn4oML",
"session_cookies": [
{
"name": "c_user",
"value": "100055829688425",
"expires": "Fri, 08 Oct 2021 07:40:01 GMT",
"expires_timestamp": 1633678801,
"domain": ".facebook.com",
"path": "/",
"secure": true
},
{
"name": "xs",
"value": "26:zj24rk1iHCRNQw:2:1602142801:-1:-1",
"expires": "Fri, 08 Oct 2021 07:40:01 GMT",
"expires_timestamp": 1633678801,
"domain": ".facebook.com",
"path": "/",
"secure": true,
"httponly": true
},
{
"name": "fr",
"value": "1f1Zr9NS95lcQZvgt.AWXy6-fEd6goo-3y9NGBO-FG6FU.BfeVtZ.NH.AAA.0.0.BffsJR.AWXNkwt0ybw",
"expires": "Wed, 06 Jan 2021 07:39:59 GMT",
"expires_timestamp": 1609918799,
"domain": ".facebook.com",
"path": "/",
"secure": true,
"httponly": true
},
{
"name": "datr",
"value": "UcJ-X0qUMXyP0GIAuWWn4oML",
"expires": "Sat, 08 Oct 2022 07:40:01 GMT",
"expires_timestamp": 1665214801,
"domain": ".facebook.com",
"path": "/",
"secure": true,
"httponly": true
}
],
"confirmed": true,
"identifier": "7736786462"
}