如何在不加载当前页面的情况下重定向到另一个jsp页面? [英] How to redirect to another jsp page without loading the current page?

查看:89
本文介绍了如何在不加载当前页面的情况下重定向到另一个jsp页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



Template.html



在这个html中文件,页眉,页脚和一些iframe元素。

 < script> 
函数callbeforeload()
{
if(condition)
{
//成功
}
else
{
window.location(exception.jsp);
}
}
< / script>

< body onload =callbeforeload();>

如果我使用window.location,它会重定向到另一个jsp页面。
我的问题是template.html不应该加载整个页面。它应该首先检查这个脚本,然后继续执行其他功能。
现在它加载整个页面(通常是iframe),然后来到这个脚本。
有没有其他方法可以实现这一点?解析方案

尝试将脚本标记作为头标记中的第一个元素。

 < head>不要将代码封装在函数中直接执行。 
< script>
if(condition)
{
//成功
}
else
{
window.location(exception.jsp);
}
< / script>


I am using a script which runs in onload event.

Template.html

In this html file, headers, footers and some iframe elements are used.

 <script>
function callbeforeload()
{
    if(condition)
    {
     //success
    }
    else
    {
    window.location("exception.jsp");
    }
}
    </script>

<body onload="callbeforeload();">

If I use window.location, it is redirecting to another jsp page. My question is template.html should not load the entire page. It should first check this script and then proceed to other function. Now it loads the entire page (normally iframe in my case) and then comes to this script. Is there any alternate way to achieve this?

解决方案

Try writing your script tag as first element in head tag. do not wrap your code inside function it will directly executed.

<head>
 <script>
  if(condition)
  {
    //success
  }
  else
  {
    window.location("exception.jsp");
  }
</script>

这篇关于如何在不加载当前页面的情况下重定向到另一个jsp页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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