Last active
April 7, 2022 03:25
-
-
Save tilfin/4992651 to your computer and use it in GitHub Desktop.
It is to easily pass data to notification html at createHTMLNotification for Chrome Extension.
The way is to store data as JSON string in location.hash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = { image: "image.jpg", text: "text..." }; | |
var popup = webkitNotifications.createHTMLNotification( | |
'notification.html#' + encodeURIComponent(JSON.stringify(data)) ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<script src="notification.js"></script> | |
</head> | |
<body> | |
<div id="content"></div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function(){ | |
var data = window.location.hash.substr(1); | |
data = JSON.parse(decodeURIComponent(data)); | |
var html = '<img src="' + data.image + '">'; | |
html += '<p class="text">' + data.text + '</p></div>'; | |
document.getElementById('content').innerHTML = html; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment