2012-06-08 6 views
1

자바 스크립트를 사용하여 하위 창에서 스크립트 파일을 추가하는 방법은 무엇입니까? 코드 위자바 스크립트를 사용하여 하위 창에 스크립트 파일을 추가하는 방법은 무엇입니까?

myWindow = window.open("", "", 'width=650,height=700,menubar=yes,resizable=yes,scrollbars=yes'); 
myWindow.focus(); 
myWindow.document.write('<script src="'+App.data.assets_url+'\/javascript\/jquery.js"><\/script>'); 

가 IE에서 제대로 작동하지 않습니다

는 다음과 같은 코드를 생각해 보자. 공백 (하위) 창을 표시하지만 크롬에서는 제대로 작동합니다. 하위 창의 모든 내용을 표시합니다.

Mozilla에서 브라우저의 인쇄 옵션이 myWindow.document.write이기 때문에 제대로 작동하지 않습니다.

$(childwindow.document.body).append('<script src="..."></script>'); 

을하지만 더 자세한 질문은 주제 답변에 더 많은 수 있습니다

+0

가능한 중복 (http://stackoverflow.com/questions/8271864/document-object-of-window-open) – Quentin

+1

응답 해주십시오과/또는 승인 된 것으로 대답을 표시하십시오. 고맙습니다. – jkrcma

답변

2

당신이 도메인 교차가없는 가정하면, 당신은 단순히이 (사용하여 jQuery를) 할 수있다.

+0

아, jQuery. 너 내 친구 야. 당신은 너무 과하게 과소 평가되어 과소 평가되었습니다. 왜 단순한 자바 스크립트 메소드가 아닌가? 오, 내 *, 천국이 베시. –

+1

나는 질문이 조금 더 정확하지 않는 한 그것을하기 위하여 보통 js 방법을 찾는 시간을 소요하고 싶지 않기 때문에 ... –

3

기본적으로 :

var win, doc; 

win = window.open('', 'dialog', opts); 
doc = win.document; 

doc.write(
    "<html><head>" 
    + "<script type='text/javascript' src='path/to/your/script.js'></script>" 
    + "<script type='text/javascript'>" 
    + "/* this is inline script inserted by JavaScript, below is a function converted to it's string representation */" 
    + someFuncInVariable.toString() 
    + "</script>" 
    + "</head><body>" 
    + "</body></html>" 
); 
doc.close(); 
[window.open의 문서 객체]의
관련 문제