我正在使用opera小部件在每个页面上提供指向我网站的链接。如何从窗口小部件中的外部源加载数据?
我想在桌面的opera小部件中显示来自sql数据库的数据。有没有办法做到这一点?是否可以从小部件中的文件中获取数据?
请指导我......
答案 0 :(得分:2)
无法从窗口小部件访问外部SQL数据库,但可以从窗口小部件读取本地文本文件。以下简单示例适用于安装了最新Opera的桌面(11.52)。
config.xml中:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" id="http://example.com/filereadertest" defaultlocale="en" width="400" height="500">
<name>File Reader Test</name>
<description>File Reader test widget</description>
<author href="http://example.com/author/">Me</author>
<feature name="http://xmlns.opera.com/fileio">
<param name="folderhint" value="home" />
</feature>
</widget>
的index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
background:#eee;
}
#output {
width:98%;
height:200px;
}
</style>
</head>
<body>
<div>
<p>Get the contents of a text file</p>
<p><textarea id="output"></textarea></p>
<p><button id="open">Open</button></p>
</div>
<script>
window.addEventListener('DOMContentLoaded', function() {
function openFile(evt) {
opera.io.filesystem.browseForFile("test", "", openFileCallback)
}
function openFileCallback(file) {
if (file) {
fstream = file.open(file, "r");
var output = document.getElementById("output");
output.value = "";
while (!fstream.eof) {
output.value += fstream.readLine("UTF-8");
}
}
}
document.getElementById("open").addEventListener("click", openFile, false);
}, false);
</script>
</body>
</html>
更多文档在这里: Widget File I/O API
答案 1 :(得分:0)
是的,但您可以在Opera小部件中使用HTML5 Web SQL Database (SQLite集成到浏览器中)