更改Chrome 4xx页面 [英] Change Chrome 4xx Page

查看:115
本文介绍了更改Chrome 4xx页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在部署一个自助服务终端系统,该系统使用Chrome浏览器显示在jetty中运行的Java Web应用程序,并使用Windows服务包装器启动。系统启动后需要一段时间才能为码头准备好提供内容,因此现在我有一个等待发生,然后在Kiosk模式下启动Chrome。这是非常丑陋,不可靠和缓慢的。

我为了使它运行更流畅而试图做的是使用检测4xx错误的Chrome扩展,设置重新加载页面的超时。我这样工作,但它仍然是一个丑陋的解决方案,因为该页面每3秒刷新一次,并且它是在用户等待期间向用户显示的糟糕!谷歌浏览器无法找到...页面。我可以通过后台的ajax请求修复第一个问题,以检测页面何时准备就绪,但我真的想向用户显示一个很好的加载屏幕而不是错误页面。我不是Chrome扩展程序开发人员,我所有尝试使用扩展程序解决此问题的尝试都失败了。



我认为可以自定义错误页面但我找不到任何有关如何做这件事的信息,因为我在主题中找到的所有搜索结果都以512最小尺寸问题为中心。

解决方案

您可以使用 webNavigation API 自定义错误页面。添加一个事件侦听器,用于onErrorOccurred事件并更新相关的详细信息。



检查示例代码作为参考。

manifest.json



注册后台页面并将所有相关权限添加到清单文件。



$ p $ {
name:自定义错误页面,
description:,
版本:1,
manifest_version:2,
background:{
scripts:[
background.js
]
},
权限:[
webNavigation,
< all_urls>
],
web_accessible_resources:[
page.html

}



background.js



重定向到我们的自定义页面以防出现任何错误,您可以将其自定义为所需的级别。

  //添加侦听器以发生错误事件
chrome.webNavigation.onErrorOccurred.addListener(function(details){
//用所需的URL更新浏览器窗口
chrome.tabs.update(details.tabId,{
url:chrome.extension.getURL(page.html)
});
});



page.html



一些简单的代码

 < html> 
< style>
body {
background:yellow;
位置:绝对;
}
< / style>

< body>
< div style =top:200px; position:absolute; left:500px; width:500; font-size:40px;>这是一个很好的描述< / div>
< / body>

< / html>



参考




  • webNavigation.onErrorOccurred

  • ul>

    I'm deploying a kiosk system that uses Chrome to display a java web app running in jetty started with a windows service wrapper. It takes some time after the system starts for jetty to be ready to serve content so for now I have a wait occurring which then launches Chrome in kiosk mode. This is pretty ugly, unreliable and slow.

    What I'm trying to do in order to make it run smoother is to use a Chrome extension that detects the 4xx error and sets a timeout that reloads the page. I have this working as is but it's still an ugly solution since the page is refreshing every 3 seconds and it's the "Oops! Google Chrome could not find..." page that's showing to the user while they're waiting. I can fix the first problem with an ajax request in the background to detect when the page is ready but I really want to show the user a nice "Loading" screen instead of the error page. I'm not a Chrome extension developer and all of my attempts to fix this with an extension have failed so far.

    I thought it would be possible to customize the error page but I can't find any information on how to do that since all of the search results I find on the topic center around the 512 minimum size issue.

    解决方案

    You can customize the error page with webNavigation API. Add an event Listener for onErrorOccurred event and update relevant details.

    Check sample code as a reference.

    Demonstration

    manifest.json

    Registered background page and added all relevant permissions to manifest file.

    {
        "name": "Customize error page",
        "description": "",
        "version": "1",
        "manifest_version": 2,
        "background": {
            "scripts": [
                "background.js"
            ]
        },
        "permissions": [
            "webNavigation",
            "<all_urls>"
        ],
        "web_accessible_resources": [
            "page.html"
        ]
    }
    

    background.js

    Redirected to our custom Page in case of any error, you can customize this to desired level.

    //Adding a Listener to Error Occured Event
    chrome.webNavigation.onErrorOccurred.addListener(function (details) {
        // Updating the browser window with desired URL
        chrome.tabs.update(details.tabId, {
            url: chrome.extension.getURL("page.html")
        });
    });
    

    page.html

    Some trivial code

    <html>
        <style>
            body {
                background:yellow;
                position:absolute;
            }
        </style>
    
        <body>
            <div style="top: 200px;position: absolute;left: 500px;width: 500;font-size: 40px;">This is a Nice Description</div>
        </body>
    
    </html>
    

    Reference

    这篇关于更改Chrome 4xx页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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