简体   繁体   English

页面重定向到另一个页面后输入凭据

[英]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.

相关问题 Vue 3成功登录后如何将用户重定向到另一个页面 - How should a user be redirected to another page after successful login in Vue 3 在重定向到另一个 HTML 页面后添加活动 class - Adding active class after being redirected to another HTML page 提交表单后从另一个页面(如确认页面)重定向后,如何将值保留在表单中 - How to keep the values in a form after getting redirected from another page(like a confirmation page) after submitting the form 成功插入数据后如何关闭此模式? 并且页面不应该被重定向到另一个页面 - How can i close this modal after the data is successfully inserted? and the page should not be redirected to another page 页面重定向到另一个页面(仪表板)后如何使用Firebase身份验证用户数据? - How to use firebase authentication user data after the page is redirected to another page (dashboard)? 即使页面被卸载或重定向到另一个页面后,如何继续AJAX / JQuery? - How to continue AJAX/JQuery even after the page is unloaded or redirected into another page? 单击轮播按钮时重定向到另一个页面 - Redirected to another page when carousel button is clicked 检查用户是否从另一个页面重定向 - Check if user is redirected from another page 脚本-打开网页,输入凭据,几秒钟后继续刷新 - Script - open a web page, enter credentials and keep on refreshing after few seconds jQuery-重定向到页面后更改页面的属性 - jQuery - change attribute of a page after being redirected to it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM