使用javascript重定向到html页面 [英] redirect to html page using javascript

查看:70
本文介绍了使用javascript重定向到html页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有2个html页面,第一个是登录页面,第二个,当我登录i重定向到主页面时,必须必须在加载时执行,只有在登录此方法后首次加载页面必须打电话。当我重新加载或刷新此方法时再次调用。



1-我可以刷新页面而不调用onload方法吗?如果是的话?





2-我可以重定向到页面中的特定方法,以避免每次都调用onload方法吗?如果是的话





3- can我在onload方法中编写任何东西,让我只在第一次调用方法?如果是的话



注意:我知道在Web应用程序中每次必须调用load函数页面重新加载,但是我有什么解决方案可以解决这个问题吗?

解决方案

两个选项:


  1. 您可以使用cookies。登录时设置cookie并在加载期间检查它。然后在执行初始化后清除它,以便下次加载检查失败。

  2. 您可以使用该地址,作为参数,如?justLoggedIn ,或 #justLoggedIn 之后的哈希值。然后检查并重定向到相同的网址减去 justLoggedIn 部分。 版本的优点是它实际上不会重新加载页面,这与使用版本时不同。


i have 2 html page the first one is the login page and the second, when i login i redirect to the main page, there is a must must execute on load, only at the first load of the page after login this method must call. when i reload or refresh this method is call again.

1- can i refresh the page without calling the onload method? if yes how?

or

2- can i redirect to a specific method in the page to avoid calling the onload method every time? if yes how

or

3- can i write any thing in the onload method that keep me calling the method only at the first time? if yes how

Note: i know that in web application it is must call load function at each time the page reload, but is there any solution that i must do to solve this problem?

解决方案

Two options:

  1. You can use cookies. Set a cookie when logging in and check for that during load. Then clear it after performing your initialization so that next load the check will fail.
  2. You can use the address, either as a parameter like ?justLoggedIn, or a value in the hash after #justLoggedIn. Then check for that and redirect to the same url minus the justLoggedIn part. The advantage of the # version is that it doesn't actually reload the page, unlike when using the ? version.

这篇关于使用javascript重定向到html页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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