session logout page issue in iframe using jsp/serv

2019-08-25 19:05发布

问题:

Hi i'm working in the web application using jsp/sevlet,i'm facing the session logout page issue in iframe

i use the following code in my parent page for my session time out

<script type="text/javascript">
    idleTime = 0;
    $(document).ready(function () {
        //Increment the idle time 2ounter every minute.
        var idleInterval = setInterval("timerIncrement()", 60000); // 1 minute

        //Zero the idle timer on mouse movement.
        $(this).mousemove(function (e) {
            idleTime = 0;
        });
        $(this).keypress(function (e) {
            idleTime = 0;
        });
    })
    function timerIncrement() {
        idleTime = idleTime + 1;
        if (idleTime == 15) { // 15 minutes
           window.location = "logoutPage.jsp"
        }
    }
</script>​​​​​​​​​​​​​​​​​​​​

the issue i'm facing is , in case a process is running beyond the session time limit in the my iframe page then the parent page is idel so it automatically getting logout

in other case if i use the session time out code in the my iframe page then the issue is

the logout page is coming inside the iframe page

Any suggestions or other explanations for solving this mystery? Please let me know

回答1:

Finally i found the solution for Iframe issue

Automatically break out of an iframe

Iframe stands for inline frame. An Iframe is a floating frame that can be inserted anywhere within a web page.

A concern for webmasters about iframes is that an iframe can be used to include pages on your website into external sites.

How do you prevent pages on your website from being included through an iframe by another website?

Placing the following javascript code at the top of all pages on your site will ensure that if any other site iframes a page on your website, that your page will break out of the iframe and just display your page in the users browser.

<script type="text/javascript">
<!--
    if (top.location!= self.location) {
        top.location = self.location.href
                   //or you can use your logout page as
                   //top.location='logout.jsp' here...
    }
//-->
</script>

The best way to implement this break out of an iframe code on an entire site is to put the code into an external javascript file, and include it in a common template file..

This will be useful for the buddies who fraught with these kind of mystery.....



回答2:

Try this if you think it is ok.

Put the iframe in a different page and include that page in your main page using JSP's include tag.

Then try and see.

I actually think iframe remains as a different from the parent page.