DOM に追加されてはじめて src が読み込まれる。
// ここでは読み込まれない
var webview = $('<webview src="http://yokano-jp.blogspot.jp/"></webview>');
webview.on('loadstop', function() {
console.log('loaded');
});
// ここではじめて読み込まれる
$('body').append(webview);
// ここでは読み込まれない
var webview = $('<webview src="http://yokano-jp.blogspot.jp/"></webview>');
webview.on('loadstop', function() {
console.log('loaded');
});
// ここではじめて読み込まれる
$('body').append(webview);
<webview src="http://hogehoge.com/" style="height: 0px; width: 0px;"></webview>
<webview src="http://hogehoge.com/" style="display: none;"></webview>
var webview = $('#my_webview');
webview.on('consolemessage', function(e) {
var message = e.originalEvent.message;
try {
var datas = JSON.parse(message);
console.log(' からデータを受け取りました', datas);
} catch(e) {
console.log(' からログが発行されました', message);
}
});
var result = {
id: 1,
value: 1234
};
var json = JSON.stringify(result);
console.log(json);
<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px" partition="persist:googlepluswidgets"></webview>
/* CSS */
#my-webview {
display: hidden;
}
<!-- HTML --> <webview id="my-webview" src="http://target-site.com/login" partition="persist:googlepluswidgets"></webview>
/* JavaScript(jQuery) */
$('#my-webview').on('loadstop', function() {
var doc = $(this.contentWindow.document);
doc.find('#login-id').val('my_id');
doc.find('#login-pass').val('my_pass');
doc.find('#login-submit').click();
});
var webview = $('#my-webview');
// webview 内で console.log() が使用されると consolemessage イベントが発生
webview.on('consolemessage', function(e) {
// 引数内の originalEvent.message にメッセージが渡される
console.log(e.originalEvent.message);
});
<webview id="foo" src="http://www.google.com/" style="width:640px; height:480px"></webview>
"background": {
"scripts": [
"foo.js",
"background.js"
]
}
/**
* インストールされた時の処理
*/
chrome.runtime.onInstalled.addListener(function() {
// ここにインストール時の処理
});
chrome.app.window.create('test.html', {
bounds: {
width: 640,
height: 480
},
frame: 'none'
});
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
</head>
<body>
......
</body>
</html>
"permissions": [
"...",
"https://supersweetdomainbutnotcspfriendly.com/"
]
{
"name": "my_app",
...
"permissions": [
"storage"
]
}
// 保存
chrome.storage.local.set({'data_key': 'data_value'});
// 取得
var value = '';
chrome.storage.local.get('value', function(item) {
value = item.value;
});
// 作成
chrome.app.window.create('my_file.html', {
bounds: {
width: 640,
height: 480
}
});
// 開いているウィンドウを閉じる
chrome.app.window.current().close();
{
"name": "Hello World!",
"description": "My first Chrome App.",
"version": "0.1",
"manifest_version": 2,
"app": {
"background": {
"scripts": ["background.js"]
}
},
"icons": { "16": "calculator-16.png", "128": "calculator-128.png" }
}
chrome.app.runtime.onLaunched.addListener(function() {
chrome.app.window.create('window.html', {
'bounds': {
'width': 400,
'height': 500
}
});
});
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div>Hello, world!</div>
</body>
</html>