简体   繁体   中英

searching with window.find and a list in browser console

In the console when I type windows.find("text") it gives me "true" or "false", which is good.

To make my job easier in checking if a list of items is present in a webpage, I want to make a script in the console

  1. list - var mylist = ["text1", "text2", "text3"]
  2. run a loop, which checks for i=0, i<mylist.length, i++* if windows.find(mylist[i])
  3. and if it is true, to list the word in the console.log.

Could you please help me with the syntax? Is my approach correct?

I guess something like

var mylist = ["text1", "text2", "text3"];

for(var val of mylist){
    if(window.find(val)) console.log(val);
}

Should do the trick? In chrome you should be able to just paste it in etc.

Edit: Adding none ES6 example also

var mylist = ["text1", "text2", "text3"];

for (var i=0;i<mylist.length;i++){
    if(window.find(mylist[i])) console.log(mylist[i]);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM