javascript - 如何设置通知声音和“橙色闪烁标签”
问题描述
我正在尝试向我的简单 php/js 聊天发出通知:
首先,我正在尝试比较我的 log.html(其中包含消息):
我原来的 post.php ( //jQuery 请求。每次用户提交表单并发送新消息时,它都会将客户端的输入和数据发送到 post.php 文件。) post.php 将消息保存到 log.html 文件中。
<?php
session_start();
if(isset($_SESSION['name'])){
$text = $_POST['text'];
$text_message = "<div class='msgln'><span class='chat-time'>".date("F j, g:i A")."</span> <b class='user-name'>".$_SESSION['name']."</b> ".stripslashes(htmlspecialchars($text))."<br></div>";
file_put_contents("log.html", $text_message, FILE_APPEND | LOCK_EX);
}
?>
我编辑的 post.php (试图设置一个函数,它正在检查“新”消息 - 与旧消息进行比较)。
<?php
session_start();
if(isset($_SESSION['name'])){
$text = $_POST['text'];
$text_message = "<div class='msgln'><span class='chat-time'>".date("F j, g:i A")."</span> <b class='user-name'>".$_SESSION['name']."</b> ".stripslashes(htmlspecialchars($text))."<br></div>";
// Check if content is different
function text_check(){
$ah = fopen("log.html", 'rb');
$aha = preg_match(fread($ah, 8192), $text_message);
$result = true;
while(!feof($ah)) {
if( $aha === false){
$result = false;
break;
}
}
fclose($ah);
return $result;
}
file_put_contents("log.html", $text_message, FILE_APPEND | LOCK_EX);
}
?>
如果 post.php 函数“text_check()”在我的 index.php 中返回 true:
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
function checkUpdate()
{
$.post("post.php", function(text_check){
if (text_check.toString()=="true") {
playSound();
}
});
}
function playSound()
{
var audio = new Audio('my_audio');
audio.play();
}
这是一个好的概念吗?
当浏览器最小化时,如何发出“橙红色闪烁”通知?
我读了一些关于标题的东西 - 必须改变它。如果我每秒都用 JS 更改它,它会起作用吗?
解决方案
推荐阅读
- oop - DDD 中聚合的存储库之间的关系
- ios - 添加第二个和第三个文本字段。只能添加第一个和最后一个
- java - stdout 运行时错误无响应 ~ HackerRank 问题
- python - 卡在python代码中进行加密。错误是“str”类型对象的未知格式代码“x”
- ios - 将最后两个小时分成 10 分钟切片
- sql - 在正确的位置添加 CASE 表达式?
- php - 显示数组而不是图像的电子邮件
- crystal-reports - 获取特定字符串中的字符串
- reactjs - ReactJs 中的 if 语句
- speech-to-text - Azure 认知服务自定义 Speech-to-Text 测试似乎被冻结,如何停止?