我在Razor视图中有以下jquery脚本,其布局设置为null。
<script type="text/javascript">
jQuery(document).ready(function () {
$('#shareapp').click(function () {
check_if_fb_is_defined();
});
window.fbactivity_id = '@Model.Id';
window.fbactivity_name = 'your-hollywood-movie';
window.wallpost_name = 'How would be your hollywood movie poster look like ?';
window.wallpost_picture = '@ViewBag.ImageURL';
window.wallpost_description = 'How would be your hollywood movie poster look like?';
window.wallpost_link = '@Html.Raw(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Action("campaign_result", "facebook", new { @resultid = Model.Id, @imgURL = ViewBag.ImageURL })))';
window.wallpost_caption = 'Ozhay';
window.tags = 'Naser';
function check_if_fb_is_defined() {
if (typeof (FB) === 'undefined') {
fbsharer();
} else {
PostShare('@Html.Raw(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Action("campaign_result", "facebook", new { @resultid = Model.Id, @imgURL = ViewBag.ImageURL})))';
}
}
function PostShare(mylink) {
FB.ui({
method: 'share',
href: mylink,
hashtag: '#Ozhay',
}, function (response) {
if (response && !response.error_message) {
ga('send', 'event', 'Wallpost', 'Facebook', window.fbactivity_name, window.fbactivity_id);
} else {
ga('send', 'event', 'Wallpost', 'No', window.fbactivity_name, window.fbactivity_id);
}
});
}
//if FB is undefined
function fbsharer() {
ga('send', 'event', 'Dialog', 'Facebook', window.fbactivity_name, window.fbactivity_id);
window.fb_sharer_url = 'https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(window.wallpost_link);
window.popupWindow = window.open(window.fb_sharer_url, 'facebooksharer', 'height=567,width=572');
var popupTimer = window.setInterval(function () {
if (typeof window.popupWindow !== 'undefined') {
if (window.popupWindow.closed !== false) {
window.clearInterval(popupTimer);
}
}
}, 200);
}
})
</script>
我已将Jquery脚本文件添加到视图中但无论出于何种原因当我单击具有shareapp
id的链接时,没有任何反应。这对我来说有点奇怪,有时候它才有效。你对此有何想法?
答案 0 :(得分:0)
FB未定义 - 您在哪里声明FB?
function check_if_fb_is_defined() {
if (typeof (FB) === 'undefined') {
fbsharer();
} else {
语法错误 - 需要&#39;)&#39;之前&#39;;&#39;在PostShare结束时。
PostShare('@Html.Raw(string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority,Url.Action("campaign_result", "facebook", new { @resultid = Model.Id, @imgURL = ViewBag.ImageURL})))';
}
}
})