[英]Activate a link click on page load based on anchor tag in URL
我在頁面上有一組鏈接,單擊這些鏈接可以啟動燈箱式彈出窗口(特別是多種語言的issuu smartlook pdf )。 我試圖找出一種方法,使它們在頁面加載時自動打開,但僅當URL中有一個定位標記時才如此。
example.com/page將正常加載頁面
example.com/page#english將使英文版在頁面加載時彈出
example.com/page#french將彈出法語版本,依此類推。
可以使用jquery來檢查window.location上的哈希,並基於此執行以下操作:
$( document ).ready(function() {
if (window.location.hash.length > 0) {
$('#' + window.location.hash).click();
//assumes you have an element with id='english', id='french', etc
}
});
我已經修改了SarahBourt的代碼以顯示模態。 我想分享一下,這對我有所幫助。
$( document ).ready(function() {
if (window.location.hash.length > 0) {
$(window.location.hash).modal('toggle');
//assumes you have an element with id='english', id='french', etc
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.