この記事では、HTML ページ上のボタンをクリックしてページを閉じるいくつかの方法を紹介します。実装のアイデアは非常にシンプルです。ウィンドウを閉じる方法はありません。プロンプトの後にページを閉じ、クリックしてこのページを閉じ、毎回他のページなどにジャンプする この方法とサンプルコードを組み合わせると非常に詳しくなりますので、必要な場合は参照してください。
HTMLページのボタンをクリックしてページを閉じる方法
1. 手段を選ばずに窓を閉める
1 |
< input type = "button" name = "close" value = "关闭" onclick = "window.close();" /> |
2. プロンプトが表示されたらページを閉じます
1 2 3 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 3 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 3 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