이 기사에서는 HTML 페이지에서 버튼을 클릭하여 페이지를 닫는 여러 가지 방법을 공유합니다. 매번 다른 페이지로 이동 등 예제 코드와 결합한 이 방법은 매우 상세하므로 필요하신 분은 참조하시기 바랍니다.
HTML 페이지에서 버튼을 클릭하여 페이지를 닫는 방법
1. 무조건 창을 닫는다
1 |
< input type = "button" name = "close" value = "关闭" onclick = "window.close();" /> |
2. 프롬프트 후 페이지를 닫습니다.
1 2 삼 4 5 6 7 8 9 10 11 12 |
< script > function custom_close(){
if(confirm("您确定要关闭本页吗?")){
window.opener=null; window.open('','_self'); window.close(); } else{
} } </ script > < input id = "btnClose" type = "button" value = "关闭本页" onClick = "custom_close()" /> |
3. 이 페이지를 닫고 다른 페이지로 이동하려면 클릭하십시오.
1 2 삼 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >html中</ title > </ head > < body onbeforeunload = "return myFunction()" > < p >该实例演示了如何向 body 元素添加 "onbeforeunload" 事件。</ p > < p >关闭当前窗口,点击以下链接触发 onbeforeunload 事件。</ p > < a href =" https://www.weidianyuedu.com">点击跳转到微点阅读</ a > < script > function myFunction() {
return "我在这写点东西..."; } </ script > </ body > </ html > |
4. 3의 방법을 js에 넣습니다.
1 2 삼 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<!DOCTYPE html> < html > < head > < meta charset = "utf-8" > < title >JavaScript 中</ title > </ head > < body > < p >该实例演示了如何使用 HTML DOM 向 body 元素添加 "onbeforeunload" 事件。</ p > < p >关闭当前窗口,按下 F5 或点击以下链接触发 onbeforeunload 事件。</ p > < a href =" https://www.weidianyuedu.com">点击调转到微点阅读网</ a > < script > window.onbeforeunload = function(event) {
event.returnValue = "我在这写点东西..."; }; </ script > </ body > </ html > |
이상으로 HTML 페이지에서 버튼을 클릭하여 페이지를 닫는 다양한 방법에 대한 글을 마치겠습니다.
재인쇄: https://www.weidianyuedu.com