PHP & JavaScript Room :: 設置サンプル

実行結果

設置サンプル

指定したURLのHTMLページを通知ウィンドウ内に表示します。
notification.html内の「遊びに来てね」リンクを押すと、別窓でトップページを開きます。

 

設置サンプルのソース

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ja" lang="ja">
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <meta http-equiv="Content-Language" content="ja" />
      <meta http-equiv="Content-Script-Type" content="text/javascript" />
      <meta http-equiv="Content-Style-Type" content="text/css" />
      <meta http-equiv="imagetoolbar" content="no" />
       <title>設置サンプル</title>
      <link rel="stylesheet" type="text/css" href="/content/lib/global.css" />
      <!-- JS -->
      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
      <script type="text/javascript" src="/content/lib/jquery/jquery.jsonp.js"></script>
      <script type="text/javascript">
         $(function(){
            /* デスクトップ通知がサポートされていないの場合 */
            if(!window.webkitNotifications){
               $("#res").html("このブラウザでは、デスクトップ通知がサポートされていません>< Google Chromeでお試しください。");
            }
            /* 【通知】ボタンをクリックした時 */
              $("#show_html_notification").click(function() {
                 showNotification();
              });
            /* 通知表示 */
              function showNotification(){
                 /* 入力されたURLを取得 */
                 var url=$("#url").val();
                 /* 未入力の場合はアラート表示 */
                 if(!url){
                    alert("URLを指定してください");
                    return;
                 }
                 /* 通知を表示する権限がある場合 */
               if (window.webkitNotifications.checkPermission() == 0) {
                  /* 通知ウィンドウ作成 */
                  window.webkitNotifications.createHTMLNotification(
                     "/content/demo/notification.html"
                  ).show();
               /* 通知を表示する権限がない場合 */
                } else {
                   /* 通知確認バー表示 */
                   RequestPermission(showNotification);
                  }
               }
               function RequestPermission(callback){
                  window.webkitNotifications.requestPermission(callback);
               }
         });
      </script>
   <link rel="stylesheet" type="text/css" href="/common/css/example.css"></head>
   <body id='example3' class='example'><div class="ads" style="margin:32px auto;text-align:center;"></div><h1 class='h'><a href='/'>PHP &amp; JavaScript Room</a> :: 設置サンプル</h1>
<h3 class='h'>実行結果</h3>
      <div id="wrap">
         <h1>設置サンプル</h1>
<!-- CODE -->
         <p id="res" style="color:red;"></p>
         <p>
            指定したURLのHTMLページを通知ウィンドウ内に表示します。<br>
            notification.html内の「遊びに来てね」リンクを押すと、別窓でトップページを開きます。
         </p>
         <p>
            <label for="url"><input type="text" id="url" value="/content/demo/notification.html" size="50" /></label> 
            <button id="show_html_notification">HTML通知を表示</button>
         </p>
<!-- / CODE -->
      </div>
   </body>
</html>