我正在为一个静态网站开发一个插件,它创建了一种社交链接储物柜。
我试图将数据从javascript传递给我的json,但是我遇到了一些问题。下面的代码片段。
它有点长,但我正在尝试将curr_page变量传递到json字符串中,以便正确地共享每个页面。如果我手动输入一个静态url按钮工作,如果我试图传递页面或curr_page变量,它不工作。
如何将curr_page变量传递到json字符串中?
<script type="text/javascript">
$(document).ready(function () {
var curr_page = window.location.href;
page = String(curr_page);
console.log(curr_page);
console.log(page);
$("#sharer").sociallocker({
text: {
header: "Grab the extra resources",
message: "Please support us, click like button below to unlock the content."
},
locker: {
close: false,
timer: 0
},
buttons: {
order: ["facebook-like", "twitter-tweet", "twitter-follow", "google-plus"]
},
facebook: {
like: {
title: "Like",
url: "https://www.facebook.com/[]"
}
},
twitter: {
tweet: {
title: "Tweet",
text: "[]",
url: page
},
follow: {
title: "Follow us",
url: "https://twitter.com/[username]"
}
},
google: {
plus: {
title: "google-share",
url: page
}
}
});
});
</script>发布于 2014-12-04 07:18:54
我希望我能理解你的意思。
如果要为JSON设置/添加值,只需执行以下操作
myJSON.myKey = "myValue";
myJSON.myKey.mySubKey = "myValue";就这些..。
发布于 2014-12-04 07:47:05
我不知道你想要什么,但是如果你只想传递当前页面,你可以直接放url: window.location.href。
这里要说明的是,这是一个javascript对象,而不是JSON字符串。您可以向url:传递变量或从函数返回。
我不明白为什么不为你工作。
检查我的Fiddle 这里
发布于 2014-12-04 07:11:21
通过传递当前页面url,您将页面重定向到它自己,并在页变量中提供到它自己的链接。
url: page在这里,url仅指当前页面。而这些点击的社交按钮只会重新加载相同的页面。
https://stackoverflow.com/questions/27288138
复制相似问题