Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <button onclick="createNotify()">Create Notify!</button>
<button onclick="notifyMe()">Notify me!</button>
              
            
!

CSS

              
                
              
            
!

JS

              
                // Case 1: 建立簡單的通知
var notifyConfig = {
  body: "\\ ^o^ /",
  icon: "https://cythilya.github.io/public/favicon.ico"
}

function createNotify() {
  if (!("Notification" in window)) { // 檢查瀏覽器是否支援通知
    console.log("This browser does not support notification");
  } else if (Notification.permission === "granted") { // 使用者已同意通知
    var notification = new Notification(
      "Thanks for granting this permission.", notifyConfig
    );
  } else if (Notification.permission !== "denied") {
    // 通知權限為 default (未要求) or undefined (老舊瀏覽器的未知狀態),向使用者要求權限
    Notification.requestPermission(function(permission) {
      if (permission === "granted") {
        var notification = new Notification("Hi there!", notifyConfig);
      }
    });
  }
}

// Case 2: 加上標籤
function notifyMe() {
  var tagList = ['newArrival', 'newFeature', 'newMsg', 'promotion'];
  var len = tagList.length;
  var times = 0;
  var timerNewArrival = setInterval(function() {
    sendNotify({
      title: tagList[times % len] + ' ' + times,
      body: '\\ ^o^ /',
      tag: tagList[times % len],
      icon: "https://cythilya.github.io/public/favicon.ico",
      url: 'http://www.ruten.com.tw/'
    });
    if (times++ == 20) {
      clearInterval(timerNewArrival);
    }
  }, 1000);
}

function sendNotify(msg) {
  var notify = new Notification(msg.title , {
    icon: msg.icon,
    body: msg.body,
    tag: msg.tag,
  });

  if(msg.url) {
    notify.onclick = function(e) { // Case 3: 綁定 click 事件
      e.preventDefault();
      window.open(msg.url);
    }
  }
}
              
            
!
999px

Console