javascript - Simulate a click with a URL parameter -
I am currently working on a page that has 4 separate tabs animated / toggled with javascript.
To use the selected tab based on a URL parameter, it should be able to anchor these tabs.
However, the only way to switch from one tab to another tab is to click on it at the moment. / P>
Therefore, I think it would be an easy way to set 4 different URLs of the page. E.g.
pagename.com # 1 pagename.com # 2 pagename.com # 3 pagename.com # 4 simulation tab of each click with each number From 1 to 4.
Can I do something like this?
Many thanks, GERAT
As the answer given above, Can change the hash by using code> window.location.hash . But, if your tab does not lock into that functionality, then the active tab will not change / change the hash only. What do you have to do in your JavaScript as a current hash and determine which tab / panel will be displayed ... See this example:
HTML:
& Lt; Div id = "tab" & gt; & Lt; Div & gt; & Lt; A href = "# 1" & gt; Tab 1 & lt; / A & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; A href = "# 2" & gt; Tab 2 & lt; / A & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; A href = "# 3" & gt; Tab 3 & lt; / A & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; A href = "# 4" & gt; Tab 4 & lt; / A & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div id = "panel" & gt; & Lt; Div id = "1" & gt; I have a panel 1 & lt; / Div & gt; & Lt; Div id = "2" & gt; I'm a panel 2 & lt; / Div & gt; & Lt; Div id = "3" & gt; I'm a panel 3 & lt; / Div & gt; & Lt; Div id = "4" & gt; I'm a panel 4 & lt; / Div & gt; & Lt; / Div & gt; CSS:
#tabs> Div {Display: Inline-Block; } #panels & gt; Div {display: none; } js:
$ (document) .ready (function () {// If you want to show the first one ... window .location .hash = '# 1'; // initially check ... var h = window.location.hash; var panel = findPanel (h); if (panel) {panelCleanUp () $ (panel) .show ( );} $ ('# Tab'). ('Click', 'a', function () {setTimeout (function () {// hash update ... var hashr = window.location.hash; var panel = FindPanel; if (panel) {panelCleanUp (); $ (panel) show ();}}, 0);});}); Function millpainel (hasher) {return $ ('# panel' + hash) [0]; } Panel's Clanup function () {$ ('# panels & gt; div') Each (function () {$ (this) .hide ();}); }
Comments
Post a Comment