如何使用JavaScript将凭据传递给iframe [英] How to pass credentials to iframe using javascript
问题描述
我正在Kibana上工作,并显示我的kibana仪表板,我在HTML中使用iframe,并且我的kibana仪表板具有[使用ReadOnlyRest插件]的身份验证.
I am working on Kibana, and to display my kibana's dashboard, I am using iframe in HTML, and my kibana dashboard has authentication [using ReadOnlyRest Plug-in].
为了传递凭据,我使用了以下格式.
To pass credentials I used the below format.
http://user1:user1 @ myhost:5601/app/kibana#/dashboard/xyz_dashboard .
现在,如果我想使用动态凭据值代替"user1:user1"
,我想使用JavaScript或Ajax或Angularjs,并使用rest.
Now if I want the dynamic credentials value in place of "user1:user1"
I want to use JavaScript or Ajax or Angularjs using rest.
我真的很空虚,搜寻了很多东西,但是什么也听不懂.
And I am seriously blank and searched a lot, but got nothing which I can understand.
请帮助我.
推荐答案
您可以尝试在js代码中创建一个变量.看看window对象,您可能很想从那里获取用户.对于前:`
You can try and make a variable in your js code.Look at the window object, you might be abble to get the user from there. For ex :`
<script>
function myFunction() {
var user = getCurrentUser(); // where getCurrentUser is a way to get the user
var source = user + "@localhost:5601/app/kibana#/dashboard/…;;";
document.getElementById("myFrame").src = source;
}
</script>`
这篇关于如何使用JavaScript将凭据传递给iframe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!