问题
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