我正在做一个歌剧扩展。扩展有一个弹出窗口,将打开一个网站在它。我得到下面的错误在"xhr.send()"在popup.html文件,我无法删除它。
"[4/14/2013 12:51:19 PM] JavaScript -部件://wuid - 9 - ec76e79 - 06 - d9 - 2749 - 8 b7e b42743de3375/popup.html内联未捕获的异常:ReferenceError:安全违规在fetchGames()中的第30行,第16列抛出错误部件://wuid - 9 - ec76e79 - 06 - d9 - 2749 - 8 b7e b42743de3375/popup.html:xhr.send ();从widget的第32行第12列调用://wuid-9ec76e79-06d9-2749-8b7e-b42743de3375/popup.html:fetchGames ();"
配置文件如下:
<?xml version="1.0" encoding="utf-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" id="http://www.example.org/helloworld">
<name>Hello Extensions!</name>
<description>A simple hello world example</description>
<author href="http://www.twitter.com/dstorey/" email="dstorey@opera.com">David Storey, Opera Software</author>
<icon src="icons/icon-64.png"/>
</widget>
我的index.html文件是:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>Hello World!</title>
<meta charset="UTF-8">
<script>
window.addEventListener( 'load', function(){
var theButton;
var ToolbarUIItemProperties = {
disabled: false,
title: 'Hello World',
icon: 'icons/icon-18.png',
popup: {
href: 'popup.html',
width: 500,
height: 500
}
}
theButton = opera.contexts.toolbar.createItem(ToolbarUIItemProperties);
opera.contexts.toolbar.addItem(theButton);
}, false );
</script>
</head>
<body>
</body>
</html>
我的popup.html文件是:
<!DOCTYPE HTML>
<html lang="en">
<head>
<title></title>
<link href="style.css" rel="stylesheet" type="text/css" />
<style type="text/css">
body {
background-color: #efefef;
}
</style>
<script>
function fetchGames() {
alert('hello');
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var data = (xhr.responseText);
document.getElementById('list_games').innerHTML = data;
//callback(data);
}
else {
alert('No Games Found');
window.close();
}
}
}
var url = 'http://www.anatomic.us/generate-xml';
xhr.open('GET', url, true);
xhr.send();
};
fetchGames();
function submitForm(obj)
{
var searchKey = document.getElementById('sp').value;
if(searchKey!=null && searchKey!='')
{
obj.setAttribute('action', 'http://www.3d-game.co/'+searchKey);
return true;
// chrome.tabs.create({url: 'http://www.3d-game.co/'+searchKey});
}
else
{
alert('Please Enter your search item');
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<!-- <div class="header">
<a href="http://www.3d-game.co/"><img src="icon.png"></a>
</div>
<br />-->
<div id=content>
<div style='padding-left:10px;'>
<form id=sf method=post action="http://www.3d-game.co/search/" onSubmit="return submitForm(this);" target="_blank">
</form>
</div>
<div id=cat_content>
<div id="list_games" class=list_games>
<img src="loader.gif" border="none" />
<div class="ajax-loader">
<img src="loader.gif" border="none" />
</div>
</div>
</div>
</body>
</html>
请帮我把它去掉
在获取数据的文件头添加以下内容:
Access-Control-Allow-Origin: *
在config.xml文件中添加这一行:允许任何域的httprequest前选项卡,这解决了问题,如果问题仍然存在,打开opera浏览器选项卡"opera:config"并选择"Users Prefs"并勾选"允许文件XMLHttpRequest"并重新启动。如果有问题,我可以给你我的opera扩展工作正常…