Skip to content

Commit ece1803

Browse files
committed
use performance.navigation.type as fallback for browsers that don't support PerformanceNavigationTiming (#2464)
1 parent 46605c0 commit ece1803

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

js/bootstrap-select.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,9 @@
14341434
titleNotAppended = !this.selectpicker.view.titleOption.parentNode,
14351435
selectedIndex = element.selectedIndex,
14361436
selectedOption = element.options[selectedIndex],
1437-
navigation = window.performance && window.performance.getEntriesByType('navigation');
1437+
navigation = window.performance && window.performance.getEntriesByType('navigation'),
1438+
// Safari doesn't support getEntriesByType('navigation') - fall back to performance.navigation
1439+
isNotBackForward = (navigation && navigation.length) ? navigation[0].type !== 'back_forward' : window.performance.navigation.type !== 2;
14381440

14391441
if (titleNotAppended) {
14401442
// Use native JS to prepend option (faster)
@@ -1454,7 +1456,7 @@
14541456
// Set selected *after* appending to select,
14551457
// otherwise the option doesn't get selected in IE
14561458
// set using selectedIndex, as setting the selected attr to true here doesn't work in IE11
1457-
if (selectTitleOption && navigation.length && navigation[0].type !== 'back_forward') {
1459+
if (selectTitleOption && isNotBackForward) {
14581460
element.selectedIndex = 0;
14591461
} else if (document.readyState !== 'complete') {
14601462
// if navigation type is back_forward, there's a chance the select will have its value set by BFCache

0 commit comments

Comments
 (0)