development

iframe 작업에서 부모 창 리디렉션

big-blog 2020. 3. 16. 08:22
반응형

iframe 작업에서 부모 창 리디렉션


iframe에서 부모 창을 리디렉션하려면 어떤 JavaScript가 필요합니까?

JavaScript 또는 다른 방법을 사용하여 부모 창을 새 URL로 리디렉션하는 하이퍼 링크를 클릭하고 싶습니다.


window.top.location.href = "http://www.example.com"; 

앞에서 언급했듯이 부모 iframe을 리디렉션합니다.


나는 그것이 <a href="..." target="_top">link</a>작동 한다는 것을 알았다


window.top.location.href = "http://example.com";

window.top 프레임 계층의 맨 위에있는 페이지의 창 개체를 나타냅니다.


또는 대안은 다음과 같습니다 (문서 객체 사용)

parent.document.location.href = "http://example.com";

target="_parent"나를 위해 일했다. 쉽고 번거 로움이 없습니다!


@MIP는 맞지만 최신 버전의 Safari에서는 iBox에 리디렉션 액세스 할 수 있도록 샌드 박스 속성 (HTML5)을 추가해야합니다. 공백 사이에 추가 할 수있는 몇 가지 특정 값이 있습니다.

참조 (스크롤해야 함) : https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe

전의:

<iframe sandbox="allow-top-navigation" src="http://google.com/"></iframe>

이것은 불행을 해결할 것입니다.

<script>parent.location='http://google.com';</script>

사용자가 별도의 조치를 취하지 않고 다른 도메인으로 리디렉션하려면 속성과 함께 링크를 사용할 수 있습니다.

target="_parent"

앞에서 말한 것처럼 다음을 사용하십시오.

document.getElementById('link').click();

자동으로 리디렉션되도록합니다.

예:

<!DOCTYPE HTML>

<html>

<head>

</head>

<body>

<a id="link" target="_parent" href="outsideDomain.html"></a>

<script type="text/javascript">
    document.getElementById('link').click();
</script>

</body>

</html>

참고 : 링크를 선언 한 후 javascript click () 명령을 사용해야합니다.


iframe에서 리디렉션 할 수 있지만 부모로부터 정보를 얻을 수는 없습니다.


window.top.location.href = 'index.html';

주 창을 색인 페이지로 리디렉션합니다. 감사


사용해보십시오

window.parent.window.location.href = 'http://google.com'

iframe 액션에서 부모 윈도우를 리디렉션하려면 window.top.location.href를 사용해야합니다.

데모 URL :


동일한 부모의 iframe으로 부모 창의 iframe을 리디렉션하십시오.

window.parent.document.getElementById("content").src = "content.aspx?id=12";

참고 URL : https://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action

반응형