programing tip

"이 창을 닫으시겠습니까?"프롬프트를받지 않고 브라우저 창을 닫으려면 어떻게해야합니까?

itbloger 2020. 10. 11. 09:12
반응형

"이 창을 닫으시겠습니까?"프롬프트를받지 않고 브라우저 창을 닫으려면 어떻게해야합니까?


이 창을 닫으 시겠습니까? 프롬프트 받지 않고 브라우저 창 을 닫으려면 어떻게해야합니까?

window.close();기능을 사용할 때 프롬프트가 표시됩니다 .


window.open('', '_self', ''); window.close();

이것은 나를 위해 작동합니다.


내 친구 ... 방법이 있지만 "해킹"은 그것을 설명하기 시작하지 않습니다. 기본적으로 IE 6 & 7의 버그를 이용해야합니다.

매번 작동합니다!

을 호출하는 대신 window.close()다른 페이지로 리디렉션합니다.

시작 페이지 :

alert("No whammies!");
window.open("closer.htm", '_self');

다른 페이지로 이동합니다. 이것은 IE를 속여이 페이지에서 브라우저를 닫도록합니다.

마감 페이지 :

<script type="text/javascript">
    window.close();
</script>

멋지죠?!


스크립트는 사용자가 연 창을 닫을 수 없습니다 . 이것은 보안 위험으로 간주됩니다. 표준이 아니지만 모든 브라우저 공급 업체는이를 따릅니다 ( Mozilla 문서 ). 일부 브라우저에서 이런 일이 발생하면 (이상적으로는) 매우 빠르게 패치되는 보안 버그입니다.

이 질문에 대한 답변의 해킹은 더 이상 작동하지 않으며 누군가가 다른 더러운 해킹을 생각해 내면 결국 작동이 중지됩니다.

이 문제를 해결하기 위해 에너지를 낭비하지 말고 브라우저가 유용하게 제공하는 방법을 수용 할 것을 제안합니다 . 페이지가 충돌하기 전에 사용자 에게 물어보십시오 .


다음은 Prompt 또는 Warning없이 브라우저를 닫는 데 사용하는 Javascript 기능입니다. Flash에서도 호출 할 수 있습니다. html 파일에 있어야합니다.

    function closeWindows() {
         var browserName = navigator.appName;
         var browserVer = parseInt(navigator.appVersion);
         //alert(browserName + " : "+browserVer);

         //document.getElementById("flashContent").innerHTML = "<br>&nbsp;<font face='Arial' color='blue' size='2'><b> You have been logged out of the Game. Please Close Your Browser Window.</b></font>";

         if(browserName == "Microsoft Internet Explorer"){
             var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;  
             if (ie7)
             {  
               //This method is required to close a window without any prompt for IE7 & greater versions.
               window.open('','_parent','');
               window.close();
             }
            else
             {
               //This method is required to close a window without any prompt for IE6
               this.focus();
               self.opener = this;
               self.close();
             }
        }else{  
            //For NON-IE Browsers except Firefox which doesnt support Auto Close
            try{
                this.focus();
                self.opener = this;
                self.close();
            }
            catch(e){

            }

            try{
                window.open('','_self','');
                window.close();
            }
            catch(e){

            }
        }
    }

본문 태그에서 :

<body onload="window.open('', '_self', '');">

창을 닫으려면 :

<a href="javascript:window.close();">

Safari 4.0.5, Mac 3.6 용 FF, IE 8.0 및 Windows 3.5 용 FF에서 테스트되었습니다.


이것은 Chrome 26, Internet Explorer 9 및 Safari 5.1.7에서 작동합니다 ( 도우미 페이지를 사용 하지 않고 Nick의 대답).

<script type="text/javascript">
    window.open('javascript:window.open("", "_self", "");window.close();', '_self');
</script>

중첩 window.open은 IE 가이 창을 닫으시겠습니까? 프롬프트 표시 하지 않도록하는 입니다.

불행히도 Firefox에서 창을 닫는 것은 불가능합니다.


보안상의 이유로 창은 JavaScript로 열린 경우에만 JavaScript에서 닫을 수 있습니다. 창을 닫으 _self려면 현재 창을 덮어 쓰는 대상으로 새 창을 열고 해당 창 을 닫아야합니다 (JavaScript를 통해 열렸 기 때문에 수행 할 수 있음).

window.open('', '_self', '');
window.close();

에서 여기 :

<a href="javascript:window.opener='x';window.close();">Close</a>

window.opener무언가 를 설정해야합니다 . 그렇지 않으면 불평합니다.


IE의 보안 강화로 인해 스크립트로 열지 않는 한 창을 닫을 수 없습니다. 따라서이 문제를 해결하는 방법은 브라우저가이 페이지가 스크립트를 사용하여 열렸다고 생각한 다음 창을 닫는 것입니다. 아래는 구현입니다.

이것을 시도하면 매력처럼 작동합니다!
자바 스크립트는 프롬프트 IE없이 현재 창 닫기

<script type="text/javascript">
function closeWP() {
 var Browser = navigator.appName;
 var indexB = Browser.indexOf('Explorer');

 if (indexB > 0) {
    var indexV = navigator.userAgent.indexOf('MSIE') + 5;
    var Version = navigator.userAgent.substring(indexV, indexV + 1);

    if (Version >= 7) {
        window.open('', '_self', '');
        window.close();
    }
    else if (Version == 6) {
        window.opener = null;
        window.close();
    }
    else {
        window.opener = '';
        window.close();
    }

 }
else {
    window.close();
 }
}
</script>

자바 스크립트는 프롬프트 IE없이 현재 창 닫기


window.open('', '_self', '').close();

여기서 조금 늦게 미안하지만 적어도 내 경우에는 해결책을 찾았습니다. Safari 11.0.3 및 Google Chrome 64.0.3282.167에서 테스트되었습니다.


JavaScript 함수 만들기

<script type="text/javascript">
    function closeme() {
        window.open('', '_self', '');
        window.close();
    }
</script>

이제이 코드를 작성하고 위의 JavaScript 함수를 호출하십시오.

<a href="Help.aspx" target="_blank" onclick="closeme();">Help</a>

또는 간단히 :

<a href="" onclick="closeme();">close</a>

window.opener=window;
window.close();

자바 스크립트로 열리지 않은 창을 닫기 위해 자바 스크립트를 사용하고 있기 때문에 브라우저가 불평하고 있습니다 window.open('foo.html');.


The best solution I have found is:

this.focus();
self.opener=this;
self.close();

Place the following code in the ASPX.

<script language=javascript>
function CloseWindow() 
{
    window.open('', '_self', '');
    window.close();
}
</script>

Place the following code in the code behind button click event.

string myclosescript = "<script language='javascript' type='text/javascript'>CloseWindow();</script>";

Page.ClientScript.RegisterStartupScript(GetType(), "myclosescript", myclosescript);

If you dont have any processing before close then you can directly put the following code in the ASPX itself in the button click tag.

OnClientClick="CloseWindow();"

Hope this helps.


This will work :

<script type="text/javascript">
function closeWindowNoPrompt()
{
window.open('', '_parent', '');
window.close();
}
</script>

In my situation the following code was embedded into a php file.

var PreventExitPop = true;
function ExitPop() {
  if (PreventExitPop != false) {
    return "Hold your horses! \n\nTake the time to reserve your place.Registrations might become paid or closed completely to newcomers!"
  }
}
window.onbeforeunload = ExitPop;

So I opened the console and write the following

PreventExitPop = false

This solved the problem. So, find out the JavaScript code and find the variable(s) and assign them to an appropriate "value" which in my case was "false"


I am going to post this because this is what I am currently using for my site and it works in both Google Chrome and IE 10 without receiving any popup messages:

<html>
    <head>
    </head>
    <body onload="window.close();">
    </body>
</html>

I have a function on my site that I want to run to save an on/off variable to session without directly going to a new page so I just open a tiny popup webpage. That webpage then closes itself immediately with the onload="window.close();" function.

참고URL : https://stackoverflow.com/questions/57854/how-can-i-close-a-browser-window-without-receiving-the-do-you-want-to-close-thi

반응형