XUL应用程序和插件的history.replaceState是否损坏? [英] Is history.replaceState broken for XUL applications and plugins?

查看:79
本文介绍了XUL应用程序和插件的history.replaceState是否损坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a browser object in my XUL application like so:

<?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是:

And the index.html is:

<!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>

打开时出现错误:

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

[Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMHistory.replaceState]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://myapp/content/index.html :: :: line 11" data: no]

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

I was trying to use Angularjs in the browser element but since it's relying on history.replaceState doing what it's supposed to do it fails in a XUL application.

[更新]

将浏览器元素的类型设置为基于内容的位置时,location.replaceState不会引发异常.

when setting type of the browser element to content-primary the location.replaceState does not throw an exception.

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

[更新]

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

XMLHttpRequest problem Status is returning 0 and Angular checks for if(status... In Firefox when opening the file from disk it would still return status 200 but not in XUL. This causes the templates not to load.

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

Changing the return in isSuccess in angular source to return (200 <= status && status < 300)||status===0; now loads the template.

[更新]

单击链接时,我看到类似#/students/22的链接变为unsafe:chrome://myapp/content/index.html#/students/22,并以一条警报结尾,告诉我不安全不是已注册的协议,这不是XUL问题.要将chrome://协议添加为Angular中受信任的协议,我在application.js中完成了以下操作:

When clicking a link I see that a link like #/students/22 becomes unsafe:chrome://myapp/content/index.html#/students/22 ending up in an alert telling me that unsafe is not a registered protocol this isn't a XUL issue. To add the chrome:// protocol as trusted in Angular I've done the following in my application.js:

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

现在它将仅打开指向chrome://path/filefile://path/file

Now it will only open links to chrome://path/file or file://path/file

推荐答案

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

Setting type of the browser element to content-primary seems to fix the location.replaceState error.

这篇关于XUL应用程序和插件的history.replaceState是否损坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆