สอบถามการทำระบบ Notify Alert หน่อยครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา สอบถามการทำระบบ Notify Alert หน่อยครับ

สอบถามการทำระบบ Notify Alert หน่อยครับ
จาก http://www.thaicreate.com/community/php-mysql-alert-notify-new-message-notification.html

ผมลองทำแล้วมันขึ้น 

alert('Your Browser Not SUPPORT Google Chrome Only');

อย่างเดียวเลยครับ ไม่ทราบว่าเป็นจากสาเหตุอะไรทั้งๆ ที่เปิดจาก Chrome และตัว notification ก็เปิดไว้ปกติ


Pusirinon 171.99.0.xxx 23-02-2016 12:14:19

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
ทดสอบหน้านี้ดู 

https://storage-cdn.realtime.co/chrome-push/index.html

แล้วคลิกปุ่มสีฟ้า send me a push notification
ถ้า chrome แจ้งเตือนว่าขออนุญาตใช้งานการแสดงข้อความ ให้กด allow หรืออนุญาต
แล้วลองกดปุ่ม สีฟ้านั้นหใม่อีกครั้ง ถ้าข้อความแสดง ก็แสดงว่าเป็นที่โค้ด
แต่ถ้าข้อความยังไม่แสดง ก็อาจจะเป็นกับ chrome เวอร์ชั่นนั้นไม่รองรับหรือไม่  
หรืออาจจะถูกปิดใช้งาน เปิดใช้งานทำได้ดังนี้


  1. Open Chrome.
  2. In the upper right corner of the browser window, click the Chrome menu Chrome menu.
  3. Click Settings > Show advanced settings.
  4. In the "Privacy" section, click Content settings.
  5. In the dialog that appears, go to "Notifications" and choose one of the following:
    • Allow all sites to show notifications: You’ll automatically see notifications from all websites.
    • Ask when a site wants to show notifications: You’ll get an alert from Chrome whenever a site wants to show you notifications. This is the default setting.
    • Do not allow any site to show notifications: You won’t see any notifications from websites.
  


ninenik 180.183.142.xxx 23-02-2016
 ความคิดเห็นที่ 2
ขึ้นครับ chrome ver.รุ่น 48.0.2564.109 m 
แต่จาก code นี้มาทำจะขึ้น 
Your Browser Not SUPPORT n Google Chrome Only อย่างเดียวเลย
อย่างนี้ผมต้องลอง โหลด version เก่ามาลงดูใช่ป่าวครับ


pusirinon 171.99.0.xxx 23-02-2016 14:21
 ความคิดเห็นที่ 3
index.php
<!DOCTYPE html>
<html>
<head>
<title>Notify Alert</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="jquery/jquery-latest.js"></script>
<meta charset=utf-8 />
<script>
  
function getDataFromDb()
{
	$.ajax({ 
				url: "getData.php" ,
				type: "POST",
				data: ''
			})
			.success(function(result) { 
				var obj = jQuery.parseJSON(result);
					if(obj != '')
					{
						  var messageid = null;
						  var subject = null;
						  $.each(obj, function(key, val) {
									messageid = val["MessageID"] ;
									subject = val["Subject"] ;
						  });

						  showPopup(messageid,subject);
					}

			});

}

if (window.webkitNotifications) {
	function requestingPopupPermission(callback) {
		window.webkitNotifications.requestPermission(callback);
	}

	function showPopup(messageid,subject) {
		if (window.webkitNotifications.checkPermission() > 0) {
			requestingPopupPermission(showPopup);
		} else {
			var mypicture = 'images/unnamed.png';
			var titletext = 'คุณมีข้อความใหม่';
			var bodytext = subject;
			var popup = window.webkitNotifications.createNotification(mypicture, titletext, bodytext);

			popup.show();

			jQuery(popup).css( 'cursor', 'pointer' );
			jQuery(popup).click(function(){
				window.location = "view.php?MessageID=" messageid;
			});

			setTimeout(function () {
				popup.cancel();
			}, '5000');
		}
	}
} else {
	alert('Your Browser Not SUPPORT n Google Chrome Only');
}

setInterval(getDataFromDb, 10000);   // 1000 = 1 second
</script>
</head>
<body>
 <center>
<h1>My Web</h1>
 <center>
</body>
</html>

ผมว่าน่าจะติดปัญหาอยู่ที่หน้านี้


pusirinon 171.99.0.xxx 23-02-2016 14:31
 ความคิดเห็นที่ 4
ดูโค้ดตามนี้เป็แแนวทาง
 
http://stackoverflow.com/questions/2271156/chrome-desktop-notification-example

หรือค้ดตัวอย่างทดสอบต่อไปนี้








<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" >
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
</head>
<body>

<div class="container" style="width:80%;margin:auto;">

 <br><br>    
<input type="button" value="Click Test" id="my_btn_1" class="btn btn-info" >
<br>
<br>

      
</div>
<script type="text/javascript">
$(function(){
    
// ตรวจสอบและขออนุญาตให้แสดงการแจ้งเตือน    
  if(Notification.permission!== "granted"){
      Notification.requestPermission();
  }    
    
    $("#my_btn_1").on("click",function(){
        notifyMe();
    });
    

    
});  
function notifyMe() {
// เมื่อบราวเซอร์ไม่รองรับ    
  if (!Notification) {
    alert('Desktop notifications not available in your browser. Try Chromium.'); 
    return;
  }

    //ตรวจสอบและขออนุญาตให้แสดงการแจ้งเตือน    
  if(Notification.permission !== "granted"){
    Notification.requestPermission();
  }else{
    // จัดรูปแบบรายการแจ้งเตือน  
    var notification = new Notification('หัวเรื่องแจ้งเตือน', {
      icon: 'https://www.ninenik.com/images/logo_01_Tue.gif',
      body: "รายละเอียดการแจ้ง!",
    });
    // เมื่อคลิกที่การแจ้งเตือน
    notification.onclick = function () {
      window.open("https://www.ninenik.com");      
    };
  }

}
</script>
</body>
</html>


ninenik 180.183.142.xxx 23-02-2016
 ความคิดเห็นที่ 5
ขอบคุณมากครับพี่


pusirinon 110.170.246.xxx 23-02-2016 16:17
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ