RT,我写了个程序,用QWebView来load一个调用了一些JS的时钟网页。这个网页用firefox是可以看到正常的时钟效果,但用我写的这个程序调用网页,时钟没有动起来,感觉是部分JS函数没有能被解析执行。这个时钟程序不知道是否是用标准的JS编写,firefox能用,我姑且认为他是标准的JS,但为什么用QWebView就不能正常显示它呢,难道不是标准JS编写的??
时钟程序的部分代码如下,请高手帮忙看下:
index.html:
<!DOCTYPE html>
<html>
<head>
<base href=".">
<script type="text/javascript">if(parent.emulator)parent.emulator.begin(window);</script>
<title>Clock</title>
<link rel="stylesheet" type="text/css" href="style.css">
<link rel="stylesheet" type="text/css" href="skins.css">
<script type="text/javascript" src="js/config.js"></script>
<script type="text/javascript" src="js/widgetModes.js"></script>
<script type="text/javascript" src="js/wdgtclock.js"></script>
</head>
<body>
<div id="dock"></div>
<div id="mainview" class="white">
<canvas width="187" height="186" id="playfield"></canvas>
<img id="gloss" src="" width="161" height="159">
<img id="dot" src="" width="20" height="20">
<p id="date"></p>
<div id="hands">
<div id="hours"></div>
<div id="minutes"></div>
<div id="seconds"></div>
</div>
</div>
</body>
</html>
js/wdgtclock.js
var ctx
,old_s_a = 0;
window.addEventListener("load",function(ev)
{
if (navigator.platform.toLowerCase().indexOf('linux') > -1 ) { document.body.className = "linux" };
ctx = document.getElementById("playfield").getContext("2d");
var d = document.getElementById('mainview');
d.className = config.SKINS[skinCounter];
var dock = document.getElementById("dock");
configure();
clock();
}
,false);
function configure()
{
var hour_css = window.getComputedStyle(document.getElementById("hours"),null)
,min_css = window.getComputedStyle(document.getElementById("minutes"),null)
,sec_css = window.getComputedStyle(document.getElementById("seconds"),null);
config.HAS_SHADOW = (hour_css.getPropertyValue("padding-top") != "none")?true:false;
config.HOUR_LENGTH = parseInt(hour_css.getPropertyValue("height"));
config.HOUR_WIDTH = parseInt(hour_css.getPropertyValue("width"));
config.HOUR_OFFSET = h_off = -parseInt(hour_css.getPropertyValue("margin-top"));
config.MIN_LENGTH = parseInt(min_css.getPropertyValue("height"));
config.MIN_WIDTH = parseInt(min_css.getPropertyValue("width"));
config.MIN_OFFSET = -parseInt(min_css.getPropertyValue("margin-top"));
config.SEC_LENGTH = parseInt(sec_css.getPropertyValue("height"));
config.SEC_WIDTH = parseInt(sec_css.getPropertyValue("width"));
config.SEC_OFFSET = -parseInt(sec_css.getPropertyValue("margin-top"));
if (hour_css.getPropertyValue("content") == "none")
{
config.GRAPHICAL = false;
config.HOUR_COLOR = hour_css.getPropertyValue("background-color");
config.MIN_COLOR = min_css.getPropertyValue("background-color");
config.SEC_COLOR = sec_css.getPropertyValue("background-color");
}
else
{
config.GRAPHICAL = true;
config.HOUR_IMAGE.src = hour_css.getPropertyValue("content");
config.MIN_IMAGE.src = min_css.getPropertyValue("content");
config.SEC_IMAGE.src = sec_css.getPropertyValue("content");
}
}
function drawShadow(offset, hand, angle)
{
ctx.save();
ctx.translate(config.WIDTH/2,config.HEIGHT/2);
ctx.translate(0,offset);
ctx.rotate(angle);
ctx.translate(-(config[hand+"_WIDTH"]/2),config[hand+"_OFFSET"]);
ctx.fillStyle = "rgba(0,0,0,0.25)";
ctx.fillRect(0,0,config[hand+"_WIDTH"]+1,config[hand+"_LENGTH"]);
ctx.restore();
}
function drawHand(hand, angle)
{
ctx.save();
ctx.translate(config.WIDTH/2,config.HEIGHT/2);
ctx.rotate(angle);
ctx.translate(-(config[hand+"_WIDTH"]/2),config[hand+"_OFFSET"]);
if (!config.GRAPHICAL)
{
ctx.fillStyle = config[hand+"_COLOR"];
ctx.fillRect(0,0,config[hand+"_WIDTH"],config[hand+"_LENGTH"]);
}
else
{
ctx.drawImage(config[hand+"_IMAGE"]);
}
ctx.restore();
}
function clock()
{
var now = new Date();
var hours = now.getHours()%12
,minutes = now.getMinutes()
,seconds = now.getSeconds()
,mseconds = config.SMOOTH?now.getMilliseconds():0;
dock.innerHTML = hours + ":" + minutes + ":" + seconds;
var h_a = (hours/6 + minutes/360 + seconds/21600)*Math.PI+Math.PI;
var m_a = (minutes/30 + seconds/1800)*Math.PI+Math.PI;
var s_a = (seconds/30 + mseconds/30000)*Math.PI+Math.PI;
if (old_s_a != s_a)
{
document.getElementById("date").textContent = now.getDate();
ctx.globalCompositeOperation = "copy";
// Draw Hours
if (config.HAS_SHADOW)
{
drawShadow(1, "HOUR", h_a);
}
ctx.globalCompositeOperation = "source-over";
drawHand("HOUR", h_a)
// Minutes
if (config.HAS_SHADOW)
{
drawShadow(2, "MIN", m_a);
}
drawHand("MIN",m_a);
// Seconds
if (config.HAS_SHADOW)
{
drawShadow(3, "SEC", s_a);
}
drawHand("SEC",s_a);
}
old_s_a = s_a;
setTimeout(clock,config.TIMEOUT);
}
var skinCounter = 0;
skinCounter = widget.preferenceForKey('skinCounter');
if(!skinCounter) skinCounter = 0;
window.addEventListener("click",setSkin,false);
function setSkin(e) {
var d = document.getElementById('mainview');
if (++skinCounter == config.SKINS.length)
{
skinCounter = 0;
}
d.className = config.SKINS[skinCounter];
configure();
widget.setPreferenceForKey(skinCounter, 'skinCounter');
}