Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/457.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript随机重定向_Javascript_Html_Redirect - Fatal编程技术网

Javascript随机重定向

Javascript随机重定向,javascript,html,redirect,Javascript,Html,Redirect,因此,我的情况如下: 我用php编写了一个提交系统,它可以写入文本文件而不是数据库,该系统的思想是人们将url提交到文本文件,然后在页面上调用该脚本时,它会重定向到文本文件之外的随机地址;问题是,我不知道如何让javascript从文本文件中读取,然后选择一行重定向到它 实际上,我只是想澄清一下,我知道如何让javascript从文本文件中读取;但我不知道如何编写一个函数,从文件中选择一个url并转发给它 鉴于我几天前遇到了这个障碍,我处理提交文件的唯一方法是每12小时检查一次文本文件,查看新提

因此,我的情况如下:

我用php编写了一个提交系统,它可以写入文本文件而不是数据库,该系统的思想是人们将url提交到文本文件,然后在页面上调用该脚本时,它会重定向到文本文件之外的随机地址;问题是,我不知道如何让javascript从文本文件中读取,然后选择一行重定向到它

实际上,我只是想澄清一下,我知道如何让javascript从文本文件中读取;但我不知道如何编写一个函数,从文件中选择一个url并转发给它

鉴于我几天前遇到了这个障碍,我处理提交文件的唯一方法是每12小时检查一次文本文件,查看新提交的文件,然后手动将其添加到此代码中:

setTimeout(function() {
var howMany = 38; 
var page = new Array(howMany+1);

page[0]="http://gproxy.nl/";
page[1]="http://homeproxy.me/";
page[2]="http://proxyturbo.com/";
page[3]="http://www.lblocker.info/";
page[4]="http://goprivate.eu/";
page[5]="http://jsproxy.com/";
page[6]="http://openthis.eu/";
page[7]="http://proxy4home.info/";
page[8]="http://dedicatedipaddress.net/";
page[9]="https://www.4everproxy.com/";
page[10]="http://www.surfsearch.info/";
page[11]="http://www.leaveproxy.com/";
page[12]="http://proxyecole.fr/";
page[13]="http://newipnow.com/";
page[14]="http://www.hiddenmode.info/";
page[15]="https://europrox.org/";
page[16]="https://www.4everproxy.com/";
page[17]="https://goingthere.org/";
page[18]="http://xuxor.com/";
page[19]="http://033b.com/";
page[20]="http://thewebtunnel.com/";
page[21]="http://prox.phanteye.com/";
page[22]="http://www.hiddenall.info/";
page[23]="http://www.5966.info/";
page[24]="http://hideyoself.com/";
page[25]="http://prox.phanteye.com/";
page[26]="http://freevideoproxy.com/";
page[27]="http://thewebtunnel.com/";
page[28]="http://openthis.eu/";
page[29]="https://europrox.org/";
page[30]="http://xuxor.com/";
page[31]="https://incloak.com/";
page[32]="http://www.leaveproxy.com/";
page[33]="http://www.openunblocker.com/";
page[34]="http://post48.com";
page[35]="http://post48.com";
page[36]="http://inteproxy.com";
page[37]="http://208.73.23.59";
page[38]="http://hidemetoday.com/";


function rndnumber(){
var randscript = -1;
while (randscript < 0 || randscript > howMany || isNaN(randscript)){
randscript = parseInt(Math.random()*(howMany+1));
}
return randscript;
}
quo = rndnumber();
quox = page[quo];
window.location=(quox);
}, 1500);
setTimeout(函数(){
var howMany=38;
var page=新数组(多少个+1);
第[0]页=”http://gproxy.nl/";
第[1]页=”http://homeproxy.me/";
第[2]页=”http://proxyturbo.com/";
第[3]页=”http://www.lblocker.info/";
第[4]页=”http://goprivate.eu/";
第[5]页=”http://jsproxy.com/";
第[6]页=”http://openthis.eu/";
第[7]页=”http://proxy4home.info/";
第[8]页=”http://dedicatedipaddress.net/";
第[9]页=”https://www.4everproxy.com/";
第[10]页=”http://www.surfsearch.info/";
第[11]页=”http://www.leaveproxy.com/";
第[12]页=”http://proxyecole.fr/";
第[13]页=”http://newipnow.com/";
第[14]页=”http://www.hiddenmode.info/";
第[15]页=”https://europrox.org/";
第[16]页=”https://www.4everproxy.com/";
第[17]页=”https://goingthere.org/";
第[18]页=”http://xuxor.com/";
第[19]页=”http://033b.com/";
第[20]页=”http://thewebtunnel.com/";
第[21]页=”http://prox.phanteye.com/";
第[22]页=”http://www.hiddenall.info/";
第[23]页=”http://www.5966.info/";
第[24]页=”http://hideyoself.com/";
第[25]页=”http://prox.phanteye.com/";
第[26]页=”http://freevideoproxy.com/";
第[27]页=”http://thewebtunnel.com/";
第[28]页=”http://openthis.eu/";
第[29]页=”https://europrox.org/";
第[30]页=”http://xuxor.com/";
第[31]页=”https://incloak.com/";
第[32]页=”http://www.leaveproxy.com/";
第[33]页=”http://www.openunblocker.com/";
第[34]页=”http://post48.com";
第[35]页=”http://post48.com";
第[36]页=”http://inteproxy.com";
第[37]页=”http://208.73.23.59";
第[38]页=”http://hidemetoday.com/";
函数rndnumber(){
var randscript=-1;
while(randscript<0 | | | randscript>有多少| | isNaN(randscript)){
randscript=parseInt(Math.random()*(howmount+1));
}
返回脚本;
}
quo=rndnumber();
quox=页面[quo];
window.location=(quox);
}, 1500);
如果有人能帮我写脚本,或者告诉我应该用谷歌搜索什么样的函数,我会非常感激,谷歌搜索“如何让javascript从文本文件读取并重定向”并没有找到多少;(


非常感谢!

如果我理解正确,首先,您需要一个正则表达式来查找文件中的URL。我将参考这篇SO帖子:

一旦你有了它,你就可以通过
window.location.href='class4'转到任何URLhttp://google.com“;

所以,你会做这样的事情

var urlPattern = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/g;
var urls = data.match(urlPattern);
if (urls) {
    window.location.href = urls[7];
}
这就是你要找的吗

或者您可以使用更简单的正则表达式,如
var urlPat=/https?:\/\/[^']+/g


记住在正则表达式中使用
/g
标志来获取所有出现的URL。

虽然这不是一个答案,但我觉得有必要指出JavaScript与Java完全不同,因此这个问题不应该列在Java类别中。为什么在运行发布的代码时不起作用?会发生什么而不是什么如果php读取文件并向客户端发送随机链接,而不是发送整个包含URL的文本文件,这不是更好吗。