如何使用javascript为iframe登录http-authentication? [英] How can I http-authentication login with javascript for an iframe?

查看:136
本文介绍了如何使用javascript为iframe登录http-authentication?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个页面


  1. 通过http-authentication自动登录网站

  2. 使用iframe显示所述网站

我以为我可以使用XHR并直接指定登录标题,然后使用javascript创建iframe。这有意义吗?是否有效?

I was thinking I could use XHR and specify the login headers directly, and then use javascript to create the iframe. Does this make sense? Will it work?

推荐答案

由于同源政策,您的XHR方法将无效。

Due to the same-origin-policy your XHR approach won't work.

但是,对于HTTP身份验证,您只需将数据包含在网址中,即<的 src ; iframe>

However, for HTTP authentication you can simply include the data in the url, i.e. the src of the <iframe>:

<iframe src="http://username:password@domain.tld/..."></iframe>

我想我不必提及如果登录凭证是敏感的,就不应该这样做 - 它们可能会出现在浏览器历史记录中。

I think I don't have to mention that this should not be done if the login credentials are sensitive - they are likely to show up in the browser history.

这篇关于如何使用javascript为iframe登录http-authentication?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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