Webプロジェクトに取り組んでいるとき、要件に遭遇しました。ページに前任者の履歴がない場合(つまり、ページは現在新しくポップアップされており、Goback操作を行うことはできません。つまり、history.go(-1))。リターンボタンをクリックするとページを直接閉じます。そうしないと、前のページに戻ります。
遭遇する問題は、歴史が後退することができるかどうかを判断する方法です。これは非常に厄介です。これは、直接取得できる機能がなく、履歴変数を通じてのみ処理できるため、非常に面倒です。ただし、IEの場合、長さの返品値は非IEの返品値とは異なります。 IE:history.length = 0、nonieは1であるため、以前に必要な関数を実装するために関数が書き込まれました。みんなと共有します。
/** *前のページに戻る(またはこのページを閉じる) * <li>前のページに履歴がない場合は、現在のページを直接閉じます</li> */function goback(){if((navigator.useragent.indexof( 'msie')> = 0) window.history.go(-1); } else {window.opener = null; window.close(); }} else {// nonie browser if(navigator.useragent.indexof( 'firefox')> = 0 || navigator.useragent.indexof.indexof.useragent.indexof( 'safari')> = 0 || navigator.useragent.index. index. index. indexof.Indexof.Indexof.Index. navigator.useragent.indexof( 'webkit')> = 0){if(window.history.length> 1){window.history.go(-1); } else {window.opener = null; window.close(); }} else {//不明なブラウザーwindow.history.go(-1); }}}