[英]enter credentials after the page is redirected to another page
I am new to JavaScript and web based programming languages. 我是JavaScript和基于Web的编程语言的新手。 What I want to do is when someone opens a particular page the user must be redirected to another page and login details should be filled by the script .
我想做的是,当某人打开特定页面时,必须将用户重定向到另一个页面,并且登录详细信息应由脚本填充。 I don't know how to do that I have tried this:
我不知道该怎么做,我已经尝试过这个:
window.location.replace("http://www.example.com/access/login/");
window.onLoad(function(){document.getElementById('username').value="xxxx"});
The problem it only redirects, but does not enter the details 它只会重定向问题,而不会输入详细信息
You cannot apply events to another page. 您无法将事件应用于其他页面。
For example, you can pass this username through GET parameter: 例如,您可以通过GET参数传递此用户名:
window.location.replace("http://www.example.com/access/login/?username=" + "xxxx");
Then, in a access/login/
page you can insert this username
using server-side language. 然后,在
access/login/
页面中,您可以使用服务器端语言插入该username
。 For example, using PHP: 例如,使用PHP:
<input type="text" id="username" name="username" value="<?php echo $_GET['username']; ?>"/>
JavaScript can work with GET parameters as well, but it is much better idea to do this at server-side. JavaScript也可以使用GET参数,但是最好在服务器端执行此操作。 If you don't have any server language, you can do this using JS:
如果您没有任何服务器语言,则可以使用JS执行此操作:
var query = window.location.search.substr(1).split('=');
if (query.length === 0) return; // no username argument
if (query.length === 2 && query[0] === 'username') {
document.getElementById('username').value = query[1];
}
My solution is definitely not the best one, it is provided just for example. 我的解决方案绝对不是最好的解决方案,仅是举例说明。 You can do this in your, more elegant and convenient way.
您可以用更优雅,更便捷的方式进行操作。
You do not have to fill the text box. 您不必填写文本框。 Just get the credentials from URL GET and pass it to login function.
只需从URL GET获取凭据并将其传递给登录功能即可。 No doubt your login page must have a login function.
毫无疑问,您的登录页面必须具有登录功能。
//First check if you have got credentials in URL
if(is_set($_GET['username']))
{
Your_Login_Function($_GET['username']), $_GET['password']))
}
//Your Page Code Here
Your_Login_Function(username, password)
{
//function process goes here
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.