Go directly to the topic and use the real-time reminder tool for new posts in the PHP + HTML5 Development Forum. Look at the development idea: In order to ensure that the browser can receive a message notification at a minimum, we need to use the HTML5 Notifications feature. Read: Notifications desktop reminder www.1990c.com? The following section takes the admin5 Forum task area as an example:
Go directly to the topic and use the real-time reminder tool for new posts in the PHP + HTML5 Development Forum. Look at the development of ideas: In order to ensure that the browser can receive a message to minimize the need to use HTML5 specifications features, recommended read: Specifications desktop reminder http://www.1990c.com /? Under p = 833, a forum in the task area of the admin5 forum is monitored as an example:
Go directly to the topic and use the real-time reminder tool for new posts in the PHP + HTML5 Development Forum.
Let's look at the development ideas:
To minimize the number of Notifications that the browser can receive, you need to use the compliance feature of html5. For more information, see:
Notifications desktop reminder
Http://www.1990c.com /? P = 833
The following uses a forum in the task area of the admin5 Forum as an example:
New post reminder tool // request desktop notification permission function init () {if (window. webkitNotifications) {window. webkitNotifications. requestPermission () ;}// Message notification function running y (str) {var icon = "logo.png "; // icon path var title = "New post reminder (" + time + "seconds later)"; // Message title var body = str; // message content var popup = window. webkitNotifications. createNotification (icon, title, body); popup. show (); // Display message} // refresh the page function refresh () {document. location. reload ();}
(. *) <\/A>/', $ str, $ titleData); $ _ SESSION ['title'] = $ titleData [1]; // capture the post title and save it to the SESSION post array echo "setTimeout ('refresh () ', $ sleep )"; // refresh page} else {// do not capture date_default_timezone_set ('prc') for the first time; $ now = mktime (); // calculate the current time $ str = file_get_contents ($ url ); preg_match_all ('/onclick = \ "atarget \ (this \) \" class = \ "xst \"> (. *) <\/a>/', $ str, $ title); // capture the post title preg_match_all ('/(. *) <\/span> <\/em>/', $ str, $ time); // capture the posting time foreach ($ ti Tle [1] as $ k => $ v) {if (! In_array ($ v, $ _ SESSION ['title']) {// determine whether it is a new post if ($ now-strtotime ($ time [2] [$ k]) <300) {// determine whether a new post is posted within 5 minutes?>
Notify ("
");
The Code has been simplified for ease of reading. You can modify the code as needed. In addition, using Ajax is also a good method.
Original article address: this is a reminder tool for new forum posts. Thank you for sharing it with me.