2012-11-13 3 views
2

현재, 나는 다음과 같은 코드를 작성 - 그러나새 창을 열기 전에 채우는 방법?

chatWindow = window.open("chatWindow.html", "Chat Window", 
resizable=0,width=700,height=600); 

var currentUserElement = chatWindow.document.createElement("currentUserElement"); 
    currentUserElement.setAttribute("id", "currentUserElement"); 
    currentUserElement.setAttribute("value",currentUserName); 

, 내가는 window.open을 호출하기 전에 먼저의 createElement() 부분을 할 수있는 방법은()가?

+1

서버가 먼저 서버를 만듭니다. :) – epascarello

답변

3

내가 클라이언트에서 수행 할 수있는 유일한 방법은 blob을 사용하는 것입니다. HTML :

<input type="text" id="textId"></input> 
<button id="buttonId">Open new Window</button> 

그리고 JS는 :

var button = $("#buttonId"); 

button.click(function() { 
    var text = $("#textId").val(); 
    var html = "<html>" 
     html += "<head><title>Window: " + text + "</title></head>"; 
     html += "<body onLoad='javascript:alert(\"" + text + "\")'>"; 
     html += text 
     html += "</body></html>"; 
    var blob = new Blob([html], {type: 'text/html'}); 
    window.open(window.URL.createObjectURL(blob)); 
});​ 

그 방법을 설명하기 위해 jsfiddle을 만들었습니다. 보시다시피 JS도 실행됩니다. 이 기술을 사용하는 html5rocks 화면 공유에 대해 흥미로운 article가 있습니다.

관련 문제