일련의 기능을 포함하는 popup.js 파일이 있습니다. 나는 새로운 탭이 생성 될 때 실행되도록 설정된 함수를 실행하려고하는데, 짧은 지연이있다. 다음은 함수 예제와 제가 시도한 솔루션입니다.크롬 확장 기능의 setTimeout 함수 popup.js 문제
// function.
function foo_bar()
{
// some ajax call.
}
// try 1
setTimeout(foo_bar,1000);
EDIT:// executed without delay.
// try 2
setTimeout(function(){
//some ajax call.
},1000)
EDIT:// executed without delay.
// try 3
setTimeout(function(){
foo_bar();
},1000)
EDIT: // didn't seem to execute.
// try 4 and 5
window.addEventListener('load',foo_bar());
window.addEventListener('DOMContentLoaded',foo_bar());
// no delay takes place. The function completes before the page even loads.
// try 6
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {...});
// used the status from here to wait till page load is complete.
//problem with this is that sometimes the status doesn't get updated.
// try 7
// tried to delay the php script by using sleep(2), but ajax call would never complete.
아무도 도와 줄 수 있습니까? 도움이되는지는 모르지만 스크립트는 배경이나 콘텐츠로 정의되어 있지 않습니다.
EDIT : 약간 자세한 내용. 호출 된 함수는 원격 서버에 대한 ajax 호출을 실행 한 다음 데이터를 기반으로 chrome.tabs.executeScript를 사용하여 새 탭이 착륙 한 페이지를 조작합니다. 유일한 문제는 페이지가 반 시간 준비되지 않은 것입니다.
시험 1에서 3까지 무엇이 잘못 되었습니까? – Dancrumb
죄송합니다. 방금 업데이트했습니다. 함수를 지연시키기 위해 지연 시간을 밀리 초 단위로 추가했습니다. 처음 두 사람은 지체없이 일했습니다. 세 가지 기능을 결코 호출하지 마십시오. – Jack