javascript 如何设置 .htaccess 密码保护提示的样式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26747171/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 06:26:04  来源:igfitidea点击:

How can I style a .htaccess password protection promp?

javascriptcss.htaccessalert

提问by Tainted

I've just been messing around with setting a password protected directory on my webserver (so as to store hot copies of backups etc.) and was wondering if there's any way I may be able to style the password prompt that appears when a user attempts to access this page.

我刚刚在我的网络服务器上设置了一个受密码保护的目录(以便存储备份的热副本等),并且想知道是否有任何方法可以设置用户尝试时出现的密码提示的样式访问此页面。

screenshot of the default prompt

默认提示截图

As it stands nobody will notice my nice little note, which makes me sad.

目前没有人会注意到我漂亮的小纸条,这让我很难过。

my prompt

我的提示

It seems to display similarly to a standard .js alert, though I've been unable to find a way to specify any css classes I may be able to alter, as the "alert" box does not show up in devtools, just the page bahind it:

它似乎显示类似于标准的 .js 警报,但我一直无法找到一种方法来指定我可能能够更改的任何 css 类,因为“警报”框没有显示在 devtools 中,只是页面隐藏它:

screenshot of html source

html源码截图

Any advice / tips would be greatly appreciated.

任何建议/提示将不胜感激。

回答by trekforever

You can't edit the authentication login box itself, it's different for every browser and its implemented as part of the browser's internals (for example, a snippet of Chrome's Code dealing with the Login Title: https://code.google.com/p/chromium/codesearch#chromium/src/chrome/app/generated_resources.grd&q=%22Authentication%20Required%22&sq=package:chromium&type=cs&l=3552).

您无法编辑身份验证登录框本身,它因每个浏览器而异,并且作为浏览器内部结构的一部分实现(例如,处理登录标题的 Chrome 代码片段:https: //code.google.com/ p/chromium/codesearch#chromium/src/chrome/app/generated_resources.grd&q=%22Authentication%20Required%22&sq=package:chromium&type=cs&l=3552)。

What you can do is to create a custom php login page (with popover if you want) to display:

您可以做的是创建一个自定义的 php 登录页面(如果需要,可以使用 popover)来显示:

Redirect 401 "authorization required page" to custom page

将401“需要授权的页面”重定向到自定义页面

Custom Login with htaccess through HTML/PHP

通过 HTML/PHP 使用 htaccess 自定义登录

Replace Htaccess popup box with a html form?

用 html 表单替换 Htaccess 弹出框?

回答by David

Add this to .htaccess

将此添加到 .htaccess

ErrorDocument 401 /401.html

Then in your root directory (where your index.html is) make your own 401.html file. If you want to make the login work, however, you'll need a server side language like PHP.

然后在您的根目录(您的 index.html 所在的位置)创建您自己的 401.html 文件。但是,如果您想让登录正常工作,则需要像 PHP 这样的服务器端语言。

回答by Bijan

From how to change the style of alert box, you cannot change the style of an alert box unless you make your own Alert Dialog (See Herefor an example)

如何更改警报框的样式,除非您制作自己的警报对话框,否则无法更改警报框的样式(请参阅此处的示例)