gpt4 book ai didi

javascript - 使用随机 URL 而不是固定 URL

转载 作者:行者123 更新时间:2023-11-28 07:34:15 25 4
gpt4 key购买 nike

我对 JS 或 Jquery 不太了解,所以非常感谢您的帮助。基本上我想使用随机 url 而不是固定的 url。可以从外部纯文本文件中获取随机 URL http://example.com/url100.txt

我在 html 页面部分中使用的当前代码如下

<script type='text/javascript'>
//<![CDATA[
var mylinks = "http://google.com";
jQuery(document).ready(function ($) {
$('#default-usage .to-lock').sociallocker({

buttons: {order:["facebook-like","twitter-tweet","google-plus"]},

twitter: {url:"http://google.com"},
facebook: {url:"http://google.com"},
google: {url:"http://google.com"},

text: {
header: "Like us To Unlock This Content",
message: "This content is locked. Like us on Twitter, Facebook or Google plus to unlock it."
},

locker: {close: false, timer: 0,},
theme: "secrets"
});
});
//]]>
</script>

所以基本上我想使用随机网址,而不是 twitter: {url:"http://example.net "}。希望我的问题很清楚

最佳答案

试试这个:

// Make sure the file is on the same server.
var file = "http://example.com/url100.txt";
$.get(file,function(txt) {

// Split data and convert it into array
var lines = txt.responseText.split("\n");
var link = lines[Math.floor(Math.random() * lines.length)];

// Apply plugin here
$('#default-usage .to-lock').sociallocker({

buttons: {order:["facebook-like","twitter-tweet","google-plus"]},
twitter: {url:link},
facebook: {url:link},
google: {url:link},

text: {
header: "Like us To Unlock This Content",
message: "This content is locked. Like us on Twitter, Facebook or Google plus to unlock it."
},

locker: {close: false, timer: 0,},
theme: "secrets"
});

});

正如您所说,您已在 BLOGSPOT 上使用它,并且文本文件存在于另一台服务器上。然后使用此解决方案。

解决方案2:

jQuery(document).ready(function ($) {

// Add link one by one in ""
var social_links = ["link1", "link2", "link3", "link4", "link5", "link6"];

var link = social_links[Math.floor(Math.random() * social_links.length)];
console.log(link);
// Apply plugin here
$('#default-usage .to-lock').sociallocker({

buttons: {order:["facebook-like","twitter-tweet","google-plus"]},
twitter: {url:link},
facebook: {url:link},
google: {url:link},

text: {
header: "Like us To Unlock This Content",
message: "This content is locked. Like us on Twitter, Facebook or Google plus to unlock it."
},

locker: {close: false, timer: 0,},
theme: "secrets"
});

});

关于javascript - 使用随机 URL 而不是固定 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28778796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com