Submitting a Keyword in HTML that goes into Javascript

[亡魂溺海] 提交于 2019-12-23 04:38:41

问题


I am looking to make a Chrome extension.. I want an Options Page where you submit a keyword:

<html>
 <head>
    <title>Options</title>
 </head>
 <body>
    Keyword:<input id="keyText" name="Keyword" type="text">
            <input name="Submit" type="submit" value="Submit">
 </body>
</html>

This javascript is supposed to refresh twitter until it find a keyword then clicks on the link in the tweet. I want this submitted keyword to be put in to a java script into the first var:

var shoeName = "";
var nikestore = "nikestore";
var closeFlag = "no";
var tFunction = "twitterScan()";
var tweet = new Array();
var tweetName = new Array();

function twitterScan() {

for (var i = 0; i < 4; i++) {
    tweetName[i] = document.getElementsByClassName("fullname js-action-profile-name show-popup-with-id")[0].innerHTML;
    tweet[i] = document.getElementsByClassName("js-tweet-text")[i].innerHTML;

}


//if (document.getElementsByClassName("fullname js-action-profile-name show-popup-with-id")[0].innerHTML;

if (tweet[0].match(shoeName) == shoeName) {
    document.getElementsByClassName("twitter-timeline-link")[0].click();
    tFunction = "get outa here";
    shoeName = " 4444  4 456 7 8 456 7 345 7 345  345 3 1 1 133s "; //buffer to jump out of interval loop

} 

else if (tweet[1].match(shoeName) == shoeName) {
    document.getElementsByClassName("twitter-timeline-link")[1].click();
    tFunction = "get outa here";
    shoeName = " 4444  4 456 7 8 456 7 345 7 345  345 3 1 1 133s "; //buffer to jump out of interval loop

}

else if (tweet[2].match(shoeName) == shoeName) {
    document.getElementsByClassName("twitter-timeline-link")[2].click();
    tFunction = "get outa here";
    shoeName = " 4444  4 456 7 8 456 7 345 7 345  345 3 1 1 133s "; //buffer to jump out of interval loop

}


else if (tweet[3].match(shoeName) == shoeName) {
    document.getElementsByClassName("twitter-timeline-link")[3].click();
    tFunction = "get outa here";
    shoeName = " 4444  4 456 7 8 456 7 345 7 345  345 3 1 1 133s "; //buffer to jump out of interval loop

}


else {
    location.reload(true);
}

setTimeout(tFunction, 700);


}

setTimeout(tFunction, 700);

//setInterval("refreshPage()", 3000);
//setTimeout("twitterScan()", 100);
//setInterval(tFunction, 700);

回答1:


HTML

Keyword:<input id="keyText" name="Keyword" type="text">
<input id="submit_button" name="Submit" type="Submit" value="Submit" onClick="javascript: twitterScan();">

JS

<script>
var shoeName = '';
function twitterScan() {
    shoeName = document.getElementById('keyText').value;
    console.log("Iam called " + shoeName);
}
</script>

Check http://jsfiddle.net/raunakkathuria/5FDT3/

Let me know if this is what you need



来源:https://stackoverflow.com/questions/20748342/submitting-a-keyword-in-html-that-goes-into-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!