Mam skrypt js który pozwala mi na przełącanie kart bez odświerzenia strony. Problem mam w tym iż na jednej z kar musi zostać wykonane odświezenie strony a wtedy powraca mi do pierwszej karty. nie wiem dokładnie jak przeskoczyc do którejś z tych kart za pomocą linku.
Oto kod js:
  1. <script type="text/javascript">
  2.  
  3.  
  4.  
  5. function ddtabcontent(tabinterfaceid){
  6. this.tabinterfaceid=tabinterfaceid //ID of Tab Menu main container
  7. this.tabs=document.getElementById(tabinterfaceid).getElementsByTagName("a") //Get all tab links within container
  8. this.enabletabpersistence=true
  9. this.hottabspositions=[] //Array to store position of tabs that have a "rel" attr defined, relative to all tab links, within container
  10. this.currentTabIndex=0 //Index of currently selected hot tab (tab with sub content) within hottabspositions[] array
  11. this.subcontentids=[] //Array to store ids of the sub contents ("rel" attr values)
  12. this.revcontentids=[] //Array to store ids of arbitrary contents to expand/contact as well ("rev" attr values)
  13. this.selectedClassTarget="link" //keyword to indicate which target element to assign "selected" CSS class ("linkparent" or "link")
  14. }
  15.  
  16. ddtabcontent.getCookie=function(Name){
  17. var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
  18. if (document.cookie.match(re)) //if cookie found
  19. return document.cookie.match(re)[0].split("=")[1] //return its value
  20. return ""
  21. }
  22.  
  23. ddtabcontent.setCookie=function(name, value){
  24. document.cookie = name+"="+value+";path=/" //cookie value is domain wide (path=/)
  25. }
  26.  
  27. ddtabcontent.prototype={
  28.  
  29. expandit:function(tabid_or_position){ //PUBLIC function to select a tab either by its ID or position(int) within its peers
  30. this.cancelautorun() //stop auto cycling of tabs (if running)
  31. var tabref=""
  32. try{
  33. if (typeof tabid_or_position=="string" && document.getElementById(tabid_or_position).getAttribute("rel")) //if specified tab contains "rel" attr
  34. tabref=document.getElementById(tabid_or_position)
  35. else if (parseInt(tabid_or_position)!=NaN && this.tabs[tabid_or_position].getAttribute("rel")) //if specified tab contains "rel" attr
  36. tabref=this.tabs[tabid_or_position]
  37. }
  38. catch(err){alert("Invalid Tab ID or position entered!")}
  39. if (tabref!="") //if a valid tab is found based on function parameter
  40. this.expandtab(tabref) //expand this tab
  41. },
  42.  
  43. cycleit:function(dir, autorun){ //PUBLIC function to move foward or backwards through each hot tab (tabinstance.cycleit('foward/back') )
  44. if (dir=="next"){
  45. var currentTabIndex=(this.currentTabIndex<this.hottabspositions.length-1)? this.currentTabIndex+1 : 0
  46. }
  47. else if (dir=="prev"){
  48. var currentTabIndex=(this.currentTabIndex>0)? this.currentTabIndex-1 : this.hottabspositions.length-1
  49. }
  50. if (typeof autorun=="undefined") //if cycleit() is being called by user, versus autorun() function
  51. this.cancelautorun() //stop auto cycling of tabs (if running)
  52. this.expandtab(this.tabs[this.hottabspositions[currentTabIndex]])
  53. },
  54.  
  55. setpersist:function(bool){ //PUBLIC function to toggle persistence feature
  56. this.enabletabpersistence=bool
  57. },
  58.  
  59. setselectedClassTarget:function(objstr){ //PUBLIC function to set which target element to assign "selected" CSS class ("linkparent" or "link")
  60. this.selectedClassTarget=objstr || "link"
  61. },
  62.  
  63. getselectedClassTarget:function(tabref){ //Returns target element to assign "selected" CSS class to
  64. return (this.selectedClassTarget==("linkparent".toLowerCase()))? tabref.parentNode : tabref
  65. },
  66.  
  67. urlparamselect:function(tabinterfaceid){
  68. var result=window.location.search.match(new RegExp(tabinterfaceid+"=(d+)", "i")) //check for "?tabinterfaceid=2" in URL
  69. return (result==null)? null : parseInt(RegExp.$1) //returns null or index, where index (int) is the selected tab's index
  70. },
  71.  
  72. expandtab:function(tabref){
  73. var subcontentid=tabref.getAttribute("rel") //Get id of subcontent to expand
  74. //Get "rev" attr as a string of IDs in the format ",john,george,trey,etc," to easily search through
  75. var associatedrevids=(tabref.getAttribute("rev"))? ","+tabref.getAttribute("rev").replace(/s+/, "")+"," : ""
  76. this.expandsubcontent(subcontentid)
  77. this.expandrevcontent(associatedrevids)
  78. for (var i=0; i<this.tabs.length; i++){ //Loop through all tabs, and assign only the selected tab the CSS class "selected"
  79. this.getselectedClassTarget(this.tabs[i]).className=(this.tabs[i].getAttribute("rel")==subcontentid)? "selected" : ""
  80. }
  81. if (this.enabletabpersistence) //if persistence enabled, save selected tab position(int) relative to its peers
  82. ddtabcontent.setCookie(this.tabinterfaceid, tabref.tabposition)
  83. this.setcurrenttabindex(tabref.tabposition) //remember position of selected tab within hottabspositions[] array
  84. },
  85.  
  86. expandsubcontent:function(subcontentid){
  87. for (var i=0; i<this.subcontentids.length; i++){
  88. var subcontent=document.getElementById(this.subcontentids[i]) //cache current subcontent obj (in for loop)
  89. subcontent.style.display=(subcontent.id==subcontentid)? "block" : "none" //"show" or hide sub content based on matching id attr value
  90. }
  91. },
  92.  
  93. expandrevcontent:function(associatedrevids){
  94. var allrevids=this.revcontentids
  95. for (var i=0; i<allrevids.length; i++){ //Loop through rev attributes for all tabs in this tab interface
  96. //if any values stored within associatedrevids matches one within allrevids, expand that DIV, otherwise, contract it
  97. document.getElementById(allrevids[i]).style.display=(associatedrevids.indexOf(","+allrevids[i]+",")!=-1)? "block" : "none"
  98. }
  99. },
  100.  
  101. setcurrenttabindex:function(tabposition){ //store current position of tab (within hottabspositions[] array)
  102. for (var i=0; i<this.hottabspositions.length; i++){
  103. if (tabposition==this.hottabspositions[i]){
  104. this.currentTabIndex=i
  105. break
  106. }
  107. }
  108. },
  109.  
  110. autorun:function(){ //function to auto cycle through and select tabs based on a set interval
  111. this.cycleit('next', true)
  112. },
  113.  
  114. cancelautorun:function(){
  115. if (typeof this.autoruntimer!="undefined")
  116. clearInterval(this.autoruntimer)
  117. },
  118.  
  119. init:function(automodeperiod){
  120. var persistedtab=0
  121. var selectedtab=-1 //Currently selected tab index (-1 meaning none)
  122. var selectedtabfromurl=this.urlparamselect(this.tabinterfaceid) //returns null or index from: tabcontent.htm?tabinterfaceid=index
  123. this.automodeperiod=automodeperiod || 0
  124. for (var i=0; i<this.tabs.length; i++){
  125. this.tabs[i].tabposition=i //remember position of tab relative to its peers
  126. if (this.tabs[i].getAttribute("rel")){
  127. var tabinstance=this
  128. this.hottabspositions[this.hottabspositions.length]=i //store position of "hot" tab ("rel" attr defined) relative to its peers
  129. this.subcontentids[this.subcontentids.length]=this.tabs[i].getAttribute("rel") //store id of sub content ("rel" attr value)
  130. this.tabs[i].onclick=function(){
  131. tabinstance.expandtab(this)
  132. tabinstance.cancelautorun() //stop auto cycling of tabs (if running)
  133. return false
  134. }
  135. if (this.tabs[i].getAttribute("rev")){ //if "rev" attr defined, store each value within "rev" as an array element
  136. this.revcontentids=this.revcontentids.concat(this.tabs[i].getAttribute("rev").split(/s*,s*/))
  137. }
  138. if (selectedtabfromurl==i || this.enabletabpersistence && selectedtab==-1 && parseInt(persistedtab)==i || !this.enabletabpersistence && selectedtab==-1 && this.getselectedClassTarget(this.tabs[i]).className=="selected"){
  139. selectedtab=i //Selected tab index, if found
  140. }
  141. }
  142. } //END for loop
  143. if (selectedtab!=-1) //if a valid default selected tab index is found
  144. this.expandtab(this.tabs[selectedtab]) //expand selected tab (either from URL parameter, persistent feature, or class="selected" class)
  145. else //if no valid default selected index found
  146. this.expandtab(this.tabs[this.hottabspositions[0]]) //Just select first tab that contains a "rel" attr
  147. if (parseInt(this.automodeperiod)>500 && this.hottabspositions.length>1){
  148. this.autoruntimer=setInterval(function(){tabinstance.autorun()}, this.automodeperiod)
  149. }
  150. } //END int() function
  151.  
  152. } //END Prototype assignment
  153. </script>