Skip to content

Commit

Permalink
Add 2 snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
Saabbir committed May 3, 2024
1 parent 699161e commit 60698e7
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
34 changes: 34 additions & 0 deletions content/snippets/safari-back-forward-cache-override.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
title: Safari back-forward-cache override
description:
#featuredImg: async.webp
createdAt: 05/03/2024
tags:
- javascript
- safari
---

<div class="c-code-wrapper">
<div class="c-code-wrapper__header">
<div class="c-code-wrapper__title">Safari back-forward-cache override</div>
<div class="c-code-wrapper__copy">Copy</div>
</div>

```js [js]
// Safari back-forward-cache override
(function () {
window.onpageshow = function (event) {
if (event.persisted) {
document.body.style.opacity = 0;
window.location.reload();
}
};
})();
```

</div>

## Further reading

- https://stackoverflow.com/a/13123626/5527156
- https://web.dev/articles/bfcache
43 changes: 43 additions & 0 deletions content/snippets/show-all-non-native-window-properties.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: Get all non native window variables
description:
#featuredImg: async.webp
createdAt: 05/03/2024
tags:
- javascript
- window
---

<div class="c-code-wrapper">
<div class="c-code-wrapper__header">
<div class="c-code-wrapper__title">Get all non native window variables</div>
<div class="c-code-wrapper__copy">Copy</div>
</div>

```js [js]
// Get all non native window variables

(function showAllNonNativeWindowProperties() {
const iframe = document.createElement("iframe");
iframe.style.display = "none";
document.body.appendChild(iframe);

const currentWindowProps = Object.getOwnPropertyNames(window);

const allNonNativeProps = currentWindowProps.filter(function (prop) {
return !iframe.contentWindow.hasOwnProperty(prop);
});

for (const prop of allNonNativeProps.sort()) {
console.log(`Saabbir ${prop}: `, window[`${prop}`]);
}

document.body.removeChild(iframe);
})();
```

</div>

## Further reading

- https://stackoverflow.com/questions/17246309/get-all-user-defined-window-properties

0 comments on commit 60698e7

Please sign in to comment.