第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

jQuery 函數(shù) history.replaceState() 從 URL 中刪除其他參數(shù)

jQuery 函數(shù) history.replaceState() 從 URL 中刪除其他參數(shù)

MMTTMM 2022-09-02 21:19:09
我有以下jQuery代碼,它在單擊后退按鈕時關(guān)閉引導模式。它工作正常。但是,當它關(guān)閉模式時,它應該從URL欄中刪除,它確實如此。但是,在這樣做的同時,它還會從URL中刪除其他“必需”參數(shù)。例如:#my-modal-id當 URL 為: 時,它可以正常工作。在這里,它根據(jù)腳本從URL欄中刪除。目前為止,一切都好。http://localhost/gamearena/index.php#my-modal-id#my-modal-id但是,當URL具有其他參數(shù)(例如)時,它會搞砸。在這里,它甚至會隨之刪除。我如何控制它,以便它只刪除之前自行設置的模態(tài)ID。http://localhost/gamearena/index.php?ref=shreyansh#sidebar-left?ref=shreyansh代碼如下:// Close model on clicking back button / swiping back  $('div.modal').on('show.bs.modal', function() {    var modal = this;    var hash = modal.id;    window.location.hash = hash;    window.onhashchange = function() {      if (!location.hash){        $(modal).modal('hide');      }    }  });  $('div.modal').on('hidden.bs.modal', function() {    var hash = this.id;    history.replaceState('', document.title, window.location.pathname);  });  // when close button clicked simulate back  $('div.modal button.close').on('click', function(){    window.history.back();  })  // when esc pressed when modal open simulate back  $('div.modal').keyup(function(e) {    if (e.keyCode == 27){      window.history.back();    }  });編輯在診斷了一點之后,我發(fā)現(xiàn)這條線負責改變這里的URL的內(nèi)容,即刪除哈希值和其他參數(shù)。此外,我注意到抓取URL只到它上面的參數(shù),而不是超出它的參數(shù)。因此,在我看來,該函數(shù)將URL恢復為狀態(tài),而不是因為它無法識別它。因此,我得出的結(jié)論是,如果被一個能夠?qū)RL提取到(添加哈希部分之前的位置)的函數(shù)替換,那么問題將得到解決。因此,請專家對此進行一些闡述。history.replaceState('', document.title, window.location.pathname);window.location.pathnameindex.phpindex.phpindex.php?ref=shreyanshwindow.location.pathnameindex.php?ref=shreyansh
查看完整描述

2 回答

?
Helenr

TA貢獻1780條經(jīng)驗 獲得超4個贊

您的代碼在設置哈希時不會更新歷史記錄,因此會恢復到較早的 URL 狀態(tài)。history.back()


這將更新哈希和歷史記錄:


function addHash (hashString) {

  let myHash = '#' + hashString;

  location.hash = myHash;

  history.replaceState(null, null, myHash);

}


查看完整回答
反對 回復 2022-09-02
?
拉莫斯之舞

TA貢獻1820條經(jīng)驗 獲得超10個贊

嘗試

window.location.hash = '';

而不是使用

window.history.back();

如果要從 URL 中刪除哈希。它還會觸發(fā)window.onhashchange


查看完整回答
反對 回復 2022-09-02
  • 2 回答
  • 0 關(guān)注
  • 420 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號