I haven’t done any programming in JavaScript, so I’m not even sure if I’m on the right track. What I want, ideally, is to open multiple windows, search them for a specific string, and close the ones that don’t find that string.
This function is just dealing with one page in one new window. The page that it opens does contain the word I’m looking for, but when I run it, returns with string not found.
function open_win() {
var wnd = window.open("http://www.bartleby.com/123/32.html");
if (wnd.find("morning")){
alert("string found");
}
else{
alert("string not found");
}
}
I modified this code to include a delay to let the page load, but now the search function doesn’t seem to work. The alert never shows up.
function open_win() {
var wnd = window.open("http://www.bartleby.com/123/32.html");
setTimeout(function(){
if (wnd.find("morning"))
{
alert("string found");
}
else
{
alert("string not found");
}
},3000);
}
A window doesn’t contain anything at the moment it is opened. You need to wait for it to load. Something along the lines of