1

我的 XUL 应用程序中有一个浏览器对象,如下所示:

<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>

<window title="Students"
        xmlns:html="http://www.w3.org/1999/xhtml"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
        width="800px"
        height="500px">
<groupbox flex="1">
  <caption label="Students"/>
  <browser type="chrome" src="chrome://myapp/content/index.html" flex="1"/>
</groupbox>   
</window>

index.html 是:

<!DOCTYPE html>
<html>
  <head>
    <title>Student page</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <h1>Something wrong with history.replaceState</h1>
    <script>
      try{
        history.replaceState(null, '', 'chrome://myapp/content/another.html');
      }catch(e){
        //not sure how to log stuff in XUL without creating helper functions
        alert(e);
      }
    </script>
  </body>
</html>

打开时出现错误:

[异常...“组件返回失败代码:0x80004005(NS_ERROR_FAILURE)[nsIDOMHistory.replaceState]”nsresult:“0x80004005(NS_ERROR_FAILURE)”位置:“JS框架:: chrome://myapp/content/index.html ::: :第11行“数据:无]

我试图在浏览器元素中使用 Angularjs,但由于它依赖 history.replaceState 做它应该做的事情,它在 XUL 应用程序中失败了。

[更新]

当将浏览器元素的类型设置为 content-primary 时,location.replaceState 不会引发异常。

  <browser type="content-primary"
    src="chrome://myapp/content/index.html" flex="1"/>

[更新]

XMLHttpRequest 问题 状态返回 0 并且 Angularif(status...在从磁盘打开文件时检查是否在 Firefox 中,它仍然会返回状态 200,但不会在 XUL 中。这会导致模板无法加载。

将角度源中 isSuccess 中的返回更改为return (200 <= status && status < 300)||status===0;现在加载模板。

[更新]

当点击一个链接时,我看到一个像这样的链接#/students/22最终unsafe:chrome://myapp/content/index.html#/students/22出现在一个警报中,告诉我 unsafe 不是注册协议,这不是 XUL 问题。要将 chrome:// 协议添加为 Angular 中受信任的协议,我在 application.js 中完成了以下操作:

angular.module('student', []).
  config(['$routeProvider','$compileProvider', 
    function($routeProvider,$compileProvider) {
      $compileProvider.urlSanitizationWhitelist(/^\s*(chrome|file):/);

现在它只会打开指向chrome://path/file或的链接file://path/file

4

1 回答 1

1

browser元素的类型设置为content-primary似乎可以修复 location.replaceState 错误。

于 2013-09-30T13:35:27.270 回答