IE8 +

2013-08-02 10 views
5

बूटस्ट्रैप में ट्विटर बूटस्ट्रैप टैब के साथ बटन हैंडलिंग वापस सक्षम करें। एक पृष्ठ पर अलग-अलग सामग्री वाले कई टैब होते हैं और उन टैब में उपयोगकर्ता को वेबसाइट पर अन्य पृष्ठों पर ले जाने के लिए लिंक होते हैं।IE8 +

दुर्भाग्य से डिफ़ॉल्ट रूप से, टैब बैक बटन नेविगेशन का समर्थन नहीं करते हैं, इसलिए यदि कोई उपयोगकर्ता किसी अन्य पृष्ठ पर जाता है और ब्राउज़र के बैक बटन को हिट करता है, तो टैब सक्रिय होने के बजाए पहले खुले टैब पर वापस आ जाएगा उन्होंने पृष्ठ को अंतिम बार देखा।

François Zaninotto से नीचे जावास्क्रिप्ट क्रोम, फ़ायरफ़ॉक्स और सफारी में इस समस्या को हल करता है। François यह भी कहता है कि यह IE8 + के लिए काम करता है - लेकिन मेरे परीक्षणों के दौरान मैं इसे IE8, IE9 या IE10 पर काम नहीं कर सकता। क्या कोई जानता है कि यह IE8 + में कैसे काम कर रहा है? क्या यह संभव है?

$(document).ready(function() { 
    // add a hash to the URL when the user clicks on a tab 
    $('a[data-toggle="tab"]').on('click', function(e) { 
    history.pushState(null, null, $(this).attr('href')); 
    }); 
    // navigate to a tab when the history changes 
    window.addEventListener("popstate", function(e) { 
    var activeTab = $('[href=' + location.hash + ']'); 
    if (activeTab.length) { 
     activeTab.tab('show'); 
    } else { 
     $('.nav-pills a:first').tab('show'); 
    } 
    }); 
}); 

`

<ul id="myTab" class="nav nav-pills"> 
       <li class="active"><a href="#tab1" data-toggle="tab">Tab1</a></li> 
       <li><a href="#tab2" data-toggle="tab">Tab2</a></li> 
     <li><a href="#tab3" data-toggle="tab">Tab3</a></li> 

      </ul> 

<div id="myTabContent" class="tab-content"> 
       <div class="tab-pane active" id="tab1"> 
        <h2>Tab 1</h2> 
       <p>Raw denim you probably haven't heard of them jean shorts Austin. Nesciunt tofu stumptown aliqua, retro synth master cleanse. Mustache cliche tempor, williamsburg carles vegan helvetica. Reprehenderit butcher retro keffiyeh dreamcatcher synth. Cosby sweater eu banh mi, qui irure terry richardson ex squid. Aliquip placeat salvia cillum iphone. Seitan aliquip quis cardigan american apparel, butcher voluptate nisi qui.</p> 
       </div> 
       <div class="tab-pane" id="tab2"> 
        <h2>Tab 2</h2> 
       <p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.</p> 
       </div> 
       <div class="tab-pane" id="tab3"> 
        <h2>Tab 3</h2> 
       <p>Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.</p> 
       </div> 
      </div> 
+0

'history.pushState' एचटीएमएल 5 है जो IE8 में समर्थित नहीं है । 'popstate' केवल आईई 10 में समर्थित है। – putvande

+0

@putvande मुझे यकीन नहीं है कि इसे कैसे कार्यान्वित किया जाए, लेकिन क्या मुझे [history.js] (https://github.com/browserstate/history.js/) का उपयोग करना चाहिए? क्या यह मेरे लिए काम करेगा? – Metzed

उत्तर

1

मैं काम से ऊपर मेरे कोड बनाने के लिए कई बार कोशिश की, लेकिन मैं को छोड़ना पड़ा और इसके बजाय मैं निम्नलिखित जावास्क्रिप्ट जो काम किया कार्यान्वित: https://gist.github.com/josheinstein/5586469

+1

आईआई 8 और क्रोम में काम करने के लिए मेरी जिंदगी यहां दी गई है: https://gist.github.com/bengm/7535223 –

1

मेरे कार्यान्वयन शायद अपनी समस्या को हल करने, ताकि अन्य जवाब के लिए कृपया प्रतीक्षा करें के लिए सबसे कारगर तरीका नहीं है।

Persist javascript variables across pages?

उपयोग जावास्क्रिप्ट सत्र टैब की अद्वितीय संख्या स्टोर करने के लिए, जैसा कि आप वर्तमान में आईडी के लिए इस्तेमाल करते हैं।

tabHistory = "tab" + currentTab; 

पिछले पृष्ठ पर वापस जाने के लिए, बस उपयोगकर्ता को tabHistory से लिंक करें।

मुझे इस तकनीक के साथ बहुत अधिक अनुभव नहीं है, केवल इसे एक बार इस्तेमाल किया जा रहा है, हालांकि इसे लागू करने के लिए त्वरित और सरल होना चाहिए, यह भी काफी कुशल है।

जो मैंने एकत्र किया है, उससे कोई काम नहीं करेगा यदि कोई नई विंडो/टैब खुलती है, लेकिन न तो बैक बटन होगा, तो यह अप्रासंगिक है।

 संबंधित मुद्दे