Nice programing

iFrame 내에서 메인 페이지를 다시로드하는 방법

nicepro 2020. 12. 28. 22:33
반응형

iFrame 내에서 메인 페이지를 다시로드하는 방법


내 시나리오에서는 일부 데이터베이스 처리를 수행하는 내 페이지의 iframe 섹션에 버튼이 있습니다.

기본적으로 필요한 것은 iframe 내에서이 버튼을 눌렀을 때 메인 페이지의 페이지 새로 고침을 수행하는 수단입니다.

iframe 내에서 트리거 할 수있는 자바 스크립트를 고맙게 생각하면 iframe을 유지하는 메인 창을 다시로드합니다.

감사. 토니.


window.top.location.reload();

상위 및 하위 iframe 도메인이 다를 경우 교차 창 보안 오류가 발생합니다.이 경우 다음을 사용할 수 있습니다.

window.parent.location = document.referrer;

window.parent.location.reload();

iframe 내부의 링크에 target = "_ parent"를 설정하여 직면 목표를 쉽게 달성 할 수 있습니다.

다음 데모 쇼와 같습니다.

<!--ParentPage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
Parent Page
<iframe src="FramePage.htm"></iframe>
</body>
</html>


<!--FramePage.htm-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<a href="http://www.g.cn" target="_parent">hello</a>
</body>
</html>

상단 프레임에 allFrame 변수를 정의하십시오.

var allFrame=1

모든 프레임에서이 기능을 확인하십시오.

if(top.allFrame === undefined)
{
    window.parent.location = "your website top frame";
}

window.opener.top.location.reload();

aspx C #으로 페이지를 코딩하면 코드를 볼 수 있습니다.

ClientScript.RegisterStartupScript(this.GetType(), "LoadParent", "<script language=javascript>window.parent.location.reload();</script>");

참조 URL : https://stackoverflow.com/questions/954454/how-to-reload-main-page-from-within-an-iframe

반응형