I've encountered a weird issue on Safari where special characters inside a <noscript> tag get escaped when using swup (first load works fine).
The issue seems to be related to how .innerHTML works and I was able to work around it using .innerText instead (.textContent seems to work too). This is most probably the line causing the issue: https://github.com/gmrchk/swup/blob/master/src/modules/getDataFromHtml.js#L6
I was trying to do some custom layout with elements inside this <noscript> when JavaScript is available, which will fallback to a simple flexbox-wrapped grid layout.
Here's the code I wrote that solves the issue. Note the use of a helper function named decodeHTML that helps getting those escaped characters unescaped again.
var getMasonryItems = function (container, selector) {
var parser = new DOMParser()
var parsedHtml = parser.parseFromString(decodeHTML(container.innerText), 'text/html')
// Both .innerText and .textContent seem to work. Don't use .innerHTML !!!
return parsedHtml.querySelectorAll(selector)
}
var decodeHTML = function (html) {
var textarea = document.createElement('textarea')
textarea.innerHTML = html
return textarea.value
}
var items = getMasonryItems(document.querySelector('noscript'), '[data-item]')
I've encountered a weird issue on Safari where special characters inside a
<noscript>tag get escaped when using swup (first load works fine).The issue seems to be related to how
.innerHTMLworks and I was able to work around it using.innerTextinstead (.textContentseems to work too). This is most probably the line causing the issue: https://github.com/gmrchk/swup/blob/master/src/modules/getDataFromHtml.js#L6I was trying to do some custom layout with elements inside this
<noscript>when JavaScript is available, which will fallback to a simple flexbox-wrapped grid layout.Here's the code I wrote that solves the issue. Note the use of a helper function named
decodeHTMLthat helps getting those escaped characters unescaped again.