2013-02-10 28 views
-1

我正在使用greasemonkey在現有網頁上操作表單。 (自動填充)Greasemonkey在表格打印結果後不再執行

表單的action屬性本身,一旦提交,它會在提交按鈕上打印成功消息。

我想要做的是,一旦表單被提交 - 我想重定向瀏覽器到另一個頁面。但這不適用於greasemonkey。什麼都沒發生。

我寫了一段代碼來檢測頁面何時提交,但在表單提交後無效。

getData("goingback"); //pulls the goingback data from database using ajax 

if (goingback == "yes") { 
    window.location = "index.php"; 
} else { 
//business as usual 

// manipulate the form and get it ready for submission 

sendPost("goback","yes"); // this function sends data to a php to be handled via ajax 

//ajax stores the data in database 

//the form is submitted using a timer and .click(); 

var submission = Math.floor(Math.random() * 10000) + 5000; 
setTimeout(function() { 
$('button[value="submit"]:first').click(); 
}, submission); 
} 

我該如何做到這一點?

在此先感謝

+1

你如何設置「返航」的值? – Dexter 2013-02-10 14:13:26

+0

通過ajax存儲在數據庫中(正確提交之前)並在頁面加載時通過ajax提取(應該在提交後發生) – 2013-02-10 14:14:22

+0

'localStorage'應該完成這項工作,只記得清除變量。如果可能,建議檢查DOM。 – 2013-02-10 14:18:45

回答

0

問題不明確;我們可能需要看到實際的頁面本身。但是,這聽起來像網頁通過AJAX提交表單,而不是一個完整的帖子。

在這種情況下,您的腳本不會反思。相反,監視成功消息的頁面。這裏有一種方法:

假設成功的消息是這樣的:

<div id="post_status"> 
    <h2>Some one set us up the (data) bomb!</h2> 
</div> 

其中<h2>的形式帖子後添加。

然後後發生此代碼後會重定向:

var postChkTimer = setInterval (checkForPostDoneNode, 200); 

function checkForPostDoneNode() { 
    var postDoneNode = $("#post_status h2"); 
    if (postDoneNode.length) { 
     window.location.assign ("index.php"); 
    } 
} 


沒有必要爲getData("goingback") sendPost("goback","yes")。此外,看起來像它的設置goback檢查goingback - 這可能是一個問題。雖然這不是導致問題中所述行爲的問題。