Chinaunix首页 | 论坛 | 博客
  • 博客访问: 830488
  • 博文数量: 67
  • 博客积分: 10067
  • 博客等级: 上将
  • 技术积分: 2175
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-12 00:00
文章分类
文章存档

2012年(1)

2011年(7)

2010年(19)

2009年(33)

2008年(7)

我的朋友

分类:

2010-02-01 11:01:19

隨便記錄一些新的javascript寫法,只在新發布的chrome4.0穩定版中可以使用的:

Web Sockets API:

if ("WebSocket" in window) {
  var ws = new WebSocket("ws://example.com/service");
  ws.onopen = function() {
    // Web Socket is connected. You can send data by send() method.
    ws.send("message to send"); ....
  };
  ws.onmessage = function (evt) { var received_msg = evt.data; ... };
  ws.onclose = function() { // websocket is closed. };
} else {
  // the browser doesn't support WebSocket.
}

ws://是一個新的標簽,其用法和http基本一樣。也可以ws://



webdatabase:

var database = openDatabase("Database Name", "Database Version");

database.executeSql("SELECT * FROM test", function(result1) {
   // do something with the results
   database.executeSql("DROP TABLE test", function(result2) {
     // do some more stuff
     alert("My second database query finished executing!");
   });
});


try {
    if (window.openDatabase) {
        db = openDatabase("NoteTest", "1.0", "HTML5 Database API example", 200000);
        if (!db)
            alert("Failed to open the database on disk.  This is probably because the version was bad or there is not enough space left in this domain's quota");
    } else
        alert("Couldn't open the database.  Please try with a WebKit nightly with this feature enabled");
} catch(err) { }


db.transaction(function(tx) {
        tx.executeSql("SELECT COUNT(*) FROM WebkitStickyNotes", [], function(result) {
            loadNotes();
        }, function(tx, error) {
            tx.executeSql("CREATE TABLE WebKitStickyNotes (id REAL UNIQUE, note TEXT, timestamp REAL, left TEXT, top TEXT, zindex REAL)", [], function(result) { 
                loadNotes(); 
            });
        });
    });

webdatabase的實現是通過本地的sqlite數據庫。




阅读(1243) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~