我想将一些参数发送到我的桌面通知,但我无法检索它们。
我用该代码打开一个通知:
var notification = webkitNotifications.createHTMLNotification(
'../html/notification.html?data='+nb
);
其中 nb 是我的变量。
通知.html:
<!DOCTYPE html>
<html>
<head>
<title>Notification</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="../js/notification.js"></script>
</head>
<body>
<div id="message">Vous avez <span></span></div>
</body>
</html>
通知.js:
function getUrlVars() {
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
var first = getUrlVars()['data'];
$('#message span').html(first +' nouveau message');
例如,结果是“Vous avez”而不是“Vous avez 1 nouveau message”。
我检查了我的 notification.js 是否已加载。如何检查“first”的值?如何调试该JS代码?或者您有更好的方法来检索 URL 中的 GET 参数吗?
非常感谢。
问候