현재 나는 내 index.html
파일어떻게
document.title = document.getElementById('title').contentWindow.document.title;
에 다음 한 index.html을 설정하는 자식은 iframe에서
어떻게 수정합니까?
현재 나는 내 index.html
파일어떻게
document.title = document.getElementById('title').contentWindow.document.title;
에 다음 한 index.html을 설정하는 자식은 iframe에서
어떻게 수정합니까?
같은 iframe
의 title
만큼 쉽게 얻기 : 당신이 iframe
가로드 title
의 값을 얻고 싶다면
var iframe = document.getElementById("iframeId");
var iframeTitle = iframe.contentDocument.title;
이 실행 :
document.getElementById("iframeId").onload = function() {
var iframeTitle = document.getElementById("iframeId").contentDocument.title;
}
title
값이 iframeTitle
에 저장되었습니다. 변하기 쉬운.
그런 다음 현재 페이지의 제목 값을이 변수로 바꿀 수 있습니다.
if (document.title != iframeTitle) {
document.title = iframeTitle;
}
당신이 당신의 html 파일에이 코드를 삽입하여 <body>
요소에 콘텐츠 뒤에 다음 코드를 추가합니다.
<script>
document.getElementById("iframeId").onload = function() {
var iframeTitle = document.getElementById("iframeId").contentDocument.title;
if (document.title != iframeTitle) {
document.title = iframeTitle;
}
}
</script>
나는 자바 스크립트가 좋지 않아 코드의 모든 부분을 어디에 넣어야합니까? – DeepMotions
@DeepMotions 위의 최신 코드 스 니펫을 참조하십시오. 닫는 '
'태그 앞에 파일의 하단에이 코드를 포함하십시오. 내가 너를 도울 수 있다면 너는 내 대답을 업 그레 이드하고 받아 들인 대답으로 표시하는 것이 좋을 것이다. – Felix
불행히도 이것도 작동하지 않았다 : ( – DeepMotions
어떤 요소가 'title'입니까? GetElementById는 ID가있는 DOM 요소를 가져 오는 데 사용됩니다. –
제목이 있어야하는 iframe의 제목은 "title"입니다. – DeepMotions
코드가 작동합니다. 아마도 프레임이로드되기 전에 실행 중일 것입니다. 참조 : https://stackoverflow.com/questions/29233928/iframe-onload-javascript-event –