• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Close a Website Page from a Different Page

We're testing the use of social media login on our website (currently looking at LoginRadius). Functionality works great but the target page gets activated and the login page is left open. Is there a way to close the login page from the target page?
0
slegy
Asked:
slegy
  • 6
  • 4
  • 2
1 Solution
 
Jesus RodriguezIT ManagerCommented:
0
 
Jesus RodriguezIT ManagerCommented:
For closing the window without confirmation you can do this

function closeWindows() {
         var browserName = navigator.appName;
         var browserVer = parseInt(navigator.appVersion);
         //alert(browserName + " : "+browserVer);

         //document.getElementById("flashContent").innerHTML = "<br>&nbsp;<font face='Arial' color='blue' size='2'><b> You have been logged out of the Game. Please Close Your Browser Window.</b></font>";

         if(browserName == "Microsoft Internet Explorer"){
             var ie7 = (document.all && !window.opera && window.XMLHttpRequest) ? true : false;  
             if (ie7)
             {  
               //This method is required to close a window without any prompt for IE7 & greater versions.
               window.open('','_parent','');
               window.close();
             }
            else
             {
               //This method is required to close a window without any prompt for IE6
               this.focus();
               self.opener = this;
               self.close();
             }
        }else{  
            //For NON-IE Browsers except Firefox which doesnt support Auto Close
            try{
                this.focus();
                self.opener = this;
                self.close();
            }
            catch(e){

            }

            try{
                window.open('','_self','');
                window.close();
            }
            catch(e){

            }
        }
    }
0
 
GeoffSuttonCommented:
window.opener will give you access to the window object of the page which opens the current window.  So window.opener.close() will programatically close the opening page.
If you want to close a page which was opened locally and now needs to be closed, use
  var win = window.open(...);
  win.close();
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
slegyAuthor Commented:
Sorry for the delay. I've been working on another problem. Will work on this this afternoon.
0
 
slegyAuthor Commented:
Thank you both. The closeWindows function works great, but it closes the current window. What I need is to close the previous activating window. The "window.opener.close()" works, but IE requests permission to close the window.  I need the activating window closed without intervention.
0
 
GeoffSuttonCommented:
In the opening window put a function, such as
function closeWindow()
{
  window.close();
}

Open in new window


Next in the opened window, call the remote function:
window.opener.closeWindow();

Open in new window


This may bypass the intrinsic security restrictions in IE.  Newer versions of IE should eliminate the problem.
0
 
slegyAuthor Commented:
I'm a little unsure how to tackle this.  Here is the entire code for the login page:

      <div id="docBody">
        <form method="post" action="" name="memLogin" id="memLogin" target="_self">
        <div id="login">
        <div id="renewHdr">
        Membership Login
        </div>
        <div id="renewText2">
        Please login using your user name and password for one of the following social media sites.</div>
        </div>
        <div id="social">
       <div id="interfacecontainerdiv" class="interfacecontainerdiv"></div>
       </div>
        </form>
            <div id="button4">
                <input name="previous" type="button" onClick="window.location='http://www.class.org/membership/joinRenew/membershipSelect.asp'" value="Previous" />
            </div>
      </div>

The page displays the header and the instructions. Below them are all the social media buttons that the member can use to login. Once the member has been verified, control is passed to the page specified with LoginRadius -- and the login page is left hanging.

Are you suggesting that the closeWindows() function provided by k-designers above be included on the login page? If so, how would it be activated?
0
 
GeoffSuttonCommented:
Yes, if you put the closeWindow function in the login page, it can be called by any page which has a reference to the login page.  In this case, that would be the joinRenew page.  So in the login page add the function inside script tags, and in the joinRenew page add code that will call window.opener.closeWindow() and that will call the closeWindow function.
0
 
slegyAuthor Commented:
I must be doing something wrong. I added the function closeWindows() to the login page. I then added: window.opener.closeWindows(); to a function in the membership page that gets activated as a part of onload processing. Works great, but it is still closing the membership page.
0
 
GeoffSuttonCommented:
Try "this.window.close()".  It seems to be using the current window object, not the originating window object.

The main problem is that you are programming against the built in idiocies in Internet Exploder, which are often difficult to get around.  I am guessing at the "this", BTW.  It is entirely possible that you will have to put up with the question, although they are considered to be the same script.

As a thought, in the onclick event, use "window open(...);window.close();".  That may solve the problem for you, since the script is being called locally and the close event is being called locally also.

Good luck.
0
 
slegyAuthor Commented:
Looking at this again today>
0
 
slegyAuthor Commented:
Not sure I'm going to get this to work, but I'll follow up on all your suggestions.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now