Skip to content

Commit

Permalink
Add resizeIframe function
Browse files Browse the repository at this point in the history
Signed-off-by: mohin7 <[email protected]>
  • Loading branch information
mohin7 committed Mar 24, 2024
1 parent cf4b418 commit 300a904
Showing 1 changed file with 19 additions and 15 deletions.
34 changes: 19 additions & 15 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@
<div class="navbar-area header--fixed">

<!-- iframe for top notification -->
<iframe src="/notification-top/" id="notification" frameborder="0" scrolling="no" style="width: 100%; display: flex; overflow: hidden;"></iframe>
<iframe src="/notification-top/" id="notification" frameborder="0" scrolling="no" onload="resizeIframe()" style="height: 0px; width: 100%; display: flex; overflow: hidden;"></iframe>
<script>
window.addEventListener("message", receiveMessageFromIframe, false);

function receiveMessageFromIframe(event) {
// Check the origin of the message for security purposes
let baseURL = "{{$.Site.BaseURL}}"

if (baseURL.endsWith("/")) {
baseURL = baseURL.slice(0, -1);
}
if (event.origin !== baseURL) {
return;
}
const notification = document.querySelector("#notification");
notification.style.height = `${event.data}px`
function resizeIframe() {
var iframe = document.getElementById("notification");
iframe.style.height = iframe.contentWindow.document.body.scrollHeight + 'px';
}
// window.addEventListener("message", receiveMessageFromIframe, false);

// function receiveMessageFromIframe(event) {
// // Check the origin of the message for security purposes
// let baseURL = "{{$.Site.BaseURL}}"

// if (baseURL.endsWith("/")) {
// baseURL = baseURL.slice(0, -1);
// }
// if (event.origin !== baseURL) {
// return;
// }
// const notification = document.querySelector("#notification");
// notification.style.height = `${event.data}px`
// }
</script>
<!-- iframe for top notification -->
<div class="navbar-area navbar-fixed">
Expand Down

0 comments on commit 300a904

Please sign in to comment.