내 최종 목표는 iframe을 복사하여 팝업 창으로 이동하는 것입니다. iframe에는 내 문제가 발생하는 많은 자바 스크립트 코드가 포함되어 있습니다.
내용을 복제하여 팝업에 추가 할 수 있습니다.
editWindow = window.open('');
Jquery
$(editWindow.document).contents().find('head').parent().replaceWith($('#box').contents().find("html").clone(true));
자바 스크립트
var head_inner = window.frames[0].document.getElementsByTagName("head")[0].cloneNode(true);
var body_inner = window.frames[0].document.getElementsByTagName("body")[0].cloneNode(true);
var old_head = editWindow.document.getElementsByTagName("head")[0];
var old_body = editWindow.document.getElementsByTagName("body")[0];
old_head.parentNode.replaceChild(head_inner, old_head);
old_body.parentNode.replaceChild(body_inner, old_body);
두 방법 모두 팝업 창에 내용을 추가하지만 거기에있는 자바 스크립트는 실행할 수 없습니다. 새 창에서 함수를 호출하려고하면 정의되지 않은 오류가 발생합니다.
javascript 실행 파일을 얻을 수있는 유일한 방법은
editWindow.document.open("text/html", "replace");
editWindow.document.write('<html>');
.....
editWindow.document.close();
그런 다음 새 창에 추가 된 코드를 실행할 수 있지만 iframe의 자바 스크립트 변수는 값을 유지하지 않습니다.
내가하려는 것이 가능합니까? 자바 스크립트 코드와 함께 전체 페이지 복제를 참조하는 것을 찾을 수 없습니다. Google은 이미 시작된 대화를 자체 창에 팝업 한 다음 다시 병합 할 수있는 Gmail 채팅과 유사한 작업을 수행하고 있습니다.
이것에 대한 통찰력을 가져 주셔서 감사합니다
HTML과 JavaScript를 소유하고 있다면 객체 자체에 상태를 저장하는 방법이 있습니다 ... t
<div id="testel" data-state="10">This is it</div>
<script>
var el = document.getElementById("testel");
// Change state
el.setAttribute("data-state", "20");
// Clone the node
var el2 = el.cloneNode(true);
// Add to the document, see the state follows.
document.getElementsByTagName("body")[0].appendChild(el2);
// This could also be serialized and sent to another window or frame.
</script>
data-*
속성에 대한 자세한 내용은 HTML5 Doctor를 참조하십시오.
편집하다
데이터를 앞뒤로 전달해야하는 경우 두 가지 방법이 있습니다.
Post Message
[해당 도메인에서] 다른 모든 창으로 메시지를 보낼 수 있으며 창에서 응답하는 메시지를 선택하고 선택할 수 있습니다.
LocalStorage를 폴링해야하지만 정보도 전달할 수 있습니다. 더 쉽게하기위한 몇 가지 래퍼가 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다