Solved

Close a Website Page from a Different Page

Posted on 2013-11-07
12
254 Views
Last Modified: 2013-11-29
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
Comment
Question by:slegy
  • 6
  • 4
  • 2
12 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
Comment Utility
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
Comment Utility
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
 
LVL 10

Expert Comment

by:GeoffSutton
Comment Utility
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
 

Author Comment

by:slegy
Comment Utility
Sorry for the delay. I've been working on another problem. Will work on this this afternoon.
0
 

Author Comment

by:slegy
Comment Utility
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
 
LVL 10

Expert Comment

by:GeoffSutton
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:slegy
Comment Utility
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
 
LVL 10

Expert Comment

by:GeoffSutton
Comment Utility
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
 

Author Comment

by:slegy
Comment Utility
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
 
LVL 10

Accepted Solution

by:
GeoffSutton earned 500 total points
Comment Utility
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
 

Author Comment

by:slegy
Comment Utility
Looking at this again today>
0
 

Author Closing Comment

by:slegy
Comment Utility
Not sure I'm going to get this to work, but I'll follow up on all your suggestions.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now