當用戶在主頁上時,他可以單擊將他重定向到另一個頁面的鏈接(到目前為止,它有效)。在新頁面中,我希望鏈接通過“自動點擊”(觸發)自動打開表格的第二個選項卡。
主頁的鏈接是特定的(它有一個錨點)。我設法制作了一個有效的腳本,問題是如果我從導航選單打開這個頁面,表格的第二個選項卡仍然打開。
我希望只有特定鏈接才能自動打開表格的第二個選項卡。
登陸頁面 服務頁面
這是我使用的代碼:
$(document).ready(function(){
$('#test').click(function(){
console.log('clicked');
});
// set time out 5 sec
setTimeout(function(){
$('.et_pb_tab_3 > a').trigger('click');
}, 500);
console.log('triggered');
});
非常感謝您的幫助。
最好的祝福,
約翰
uj5u.com熱心網友回復:
一個 url 引數可能會為您完成作業。從鏈接要打開,你可以這樣做:example-link.com?showTable=True。
然后在新頁面上查找該 url 引數,只有在它存在且為 True 時才打開。
example-link.com#rebozo?showTable=True
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const product = urlParams.get('showTable')
if (showTable && showTable === 'True') {
// code to open the table
}
https://www.sitepoint.com/get-url-parameters-with-javascript/
uj5u.com熱心網友回復:
好的,這很容易,我要感謝@Branson Smith 的靈感。
我只是有條件陳述句來檢查 url 中是否有散列:
if (window.location.hash == '#myHash') {
$(document).ready(function(){
$('#myID').click(function(){
console.log('clicked');
});
setTimeout(function(){
$('.myClass > a').trigger('click');
}, 2000);
console.log('triggered');
});
};
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/384228.html
標籤:javascript 查询 WordPress的 触发器 锚
