2012-04-16 4 views
0

내 프로젝트에서는 document.write를 통해 스크립트에서 동적으로 생성 된 태그를 식별해야합니다. 난 document.write를위한 후크를 생성하지만userscript를 사용하여 document.write의 매개 변수를 검색하는 방법

UPDATE 다음 모든 document.write를 functions.My의 코드가 검색되지 않는다 :

var oldDocumentWrite = document.write; 
document.write  = function (text) 
{   
    console.log(text); 
} 

document.write를 텍스트의 파라미터이다.

나는 이것을 내 사용자 스크립트에 포함 시켰습니다. document.write의 매개 변수를 가져 오는 방법은 무엇입니까? 내 코드에 실수가 있습니까?

+3

솔루션 : 예를 정규식으로 HTML을 구문 분석하지만, DOM 방법을 사용하지 마십시오'document.getElementsByTagName ('스크립트') ', 또는 DOM 돌연변이 이벤트 :'DOMNodeInserted'. –

+0

'document.getElementsByTagName ('script');'동적으로 생성 된 태그를 검색하지 않습니다. – user1335906

+0

분명히 요소 삽입 감지 방법과 함께. –

답변

0

아래 코드를 사용하여 다시 시도해 보았습니다. 지금 모든 document.write 메소드를 얻고 있습니다.

var oldDocumentWrite = document.write; 
document.write  = function (str) 
{   
    var elem = oldDocumentWrite.apply (document,arguments); 
    console.log("Document.write Parameters:",str); 
    return elem; 
} 
관련 문제