簡體   English   中英

JavaScript隨機重定向

[英]Javascript random redirect

所以我的情況如下:

我用php編寫了一個提交系統,該系統寫一個文本文件而不是數據庫,該系統的想法是人們將其URL提交到文本文件,然后在頁面上調用該腳本時,它將重定向到一個隨機地址。文本文件; 問題是,我不知道如何從文本文件中讀取javascript,然后選擇要重定向的行。

實際上,為了澄清起見,我知道如何使javascript從文本文件中讀取。 但我不知道id如何編寫一個函數來從文件中選擇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);

如果有人能幫助我編寫腳本或告訴我應該使用哪種功能進行查找,使用谷歌搜索“如何從文本文件中讀取JavaScript並進行重定向”並沒有帶來太多幫助,我將不勝感激;

非常感謝!

如果我理解正確,首先,您需要一個正則表達式來找到文件中的URL。 我將為此參考該SO帖子: URL的正則表達式

有了它,您就可以使用window.location.href = 'http://google.com';轉到任何URL window.location.href = 'http://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。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM