<title>中的网络通知来自聊天框 [英] web notifications in <title> from chatbox

查看:52
本文介绍了<title>中的网络通知来自聊天框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将网络通知放在我网页的标题/标签屏幕中.因此,每当有人新说某事并且您不在选项卡上时,它都会通知您有新消息.

I'm trying to put web notifications in the title/tab screen of my webpage. So whenever someone new says something and you're not on the tab, the will give notifications that you have a new message.

有没有什么简单的方法可以解决这个问题?这是聊天的实时链接我必须篡改我的 post.php 吗?或者会

Is there any simple way to go about this? Here's a live link of the chat would i have to tamper with my post.php? or would

<?
session_start();
 if(isset($_SESSION['name'])){
$text = $_POST['text']; 
$fp = fopen("log.html", 'a');
fwrite($fp, "<div class='msgln'> C:\Users\<b>".$_SESSION['name']."></b> ".stripslashes(htmlspecialchars($text))."<br></div>");
fclose($fp);
}
?>

或者我会篡改输入吗?

$(document).ready(function(){
//If user submits the form
$("#submitmsg").click(function(){   
    var clientmsg = $("#usermsg").val();
    $.post("post.php", {text: clientmsg});              
    $("#usermsg").attr("value", "");
    return false;
});

在此先感谢您的帮助!

推荐答案

我建议你看看 JavaScript 函数 setInterval().如果发现任何更新,则使此函数每 x 毫秒检查一次更新;编辑页面标题.

I'd suggest you to have a look at the JavaScript function setInterval(). Make this function check for updates every x ms, if it finds any updates; edit the page-title.

这样的事情应该可以解决问题,调整以获得首选结果:

Something like this should do the trick, tweak to get preferred result:

// This function will run every ~1s
setInterval(function() {

   // Get the new data
   $.post('post.php', function(data) {

      // Handle the data
      document.title = data;

   });


}, 1000);

您绝对应该在 PHP 脚本上添加一些错误检查(检查是否设置了变量:isset($_SESSION['value'])),也可能在 javascript 中.

You should definitely add some error checking on the PHP-script (check if variables are set: isset($_SESSION['value'])), possibly at the javascript too.

这篇关于&lt;title&gt;中的网络通知来自聊天框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆