[英]How to open search result page in new window for javascript search engine which works in IE?
[英]JavaScript - Open new page and search in it
我還沒有用JavaScript進行任何編程,所以我什至不確定自己是否走對了。 理想情況下,我想要打開多個窗口,在它們中搜索特定的字符串,然后關閉找不到該字符串的窗口。
此功能僅在一個新窗口中處理一頁。 它打開的頁面確實包含我要查找的單詞,但是當我運行它時,返回的字符串未找到。
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");
}
}
我修改了這段代碼,以包含讓頁面加載的延遲,但是現在搜索功能似乎無法正常工作。 警報從不顯示。
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);
}
窗口在打開時不包含任何內容。 您需要等待它加載。 遵循以下原則
function open_win() {
var wnd = window.open("http://www.bartleby.com/123/32.html");
wnd.addEventListener("load",function(){
if (wnd.find("morning")){
alert("string found");
}
else{
alert("string not found");
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.