【问题标题】:redirect to html page using javascript使用javascript重定向到html页面
【发布时间】:2012-06-18 13:36:54
【问题描述】:

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

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

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

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

注意: 我知道在 web 应用程序中,每次重新加载页面时都必须调用 load 函数,但是我必须采取任何解决方案来解决这个问题吗?

【问题讨论】:

  • 您指的是页面中的方法。这是 ASP.NET 吗?
  • 我假设你不使用 servlet 对吗!?
  • 不,它不是 ASP.NET,我不正确使用 servlet

标签: javascript jquery html redirect


【解决方案1】:

两种选择:

  1. 您可以使用cookies。登录时设置一个 cookie,并在加载期间检查它。然后在执行初始化后清除它,以便下次加载检查将失败。
  2. 您可以将地址用作?justLoggedIn 之类的参数,或#justLoggedIn 之后的哈希值。然后检查并重定向到相同的 url 减去 justLoggedIn 部分。 # 版本的优势在于它实际上不会重新加载页面,这与使用 ? 版本时不同。

【讨论】:

  • 我使用cookies,这是参考网站blogs.x2line.com/al/articles/316.aspx谢谢Supr
  • 您必须小心,尽管在使用 cookie 选项作为安全角度时,cookie 可能会被 firebug 等浏览器工具删除,对吗?!
【解决方案2】:

你可以通过重定向来刷新页面

[urlOfCurrentPage] + "?redirected=true"

然后在onLoad方法中检查URL中是否有GET“redirected”参数,如果有则跳过onload。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-24
    • 1970-01-01
    • 2016-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多