Solved

Close a Website Page from a Different Page

Posted on 2013-11-07
12
269 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
  • 2
12 Comments
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39631045
0
 
LVL 13

Expert Comment

by:Jesus Rodriguez
ID: 39631053
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
ID: 39632571
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!

 

Author Comment

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

Author Comment

by:slegy
ID: 39637390
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
ID: 39637449
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
 

Author Comment

by:slegy
ID: 39637498
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
ID: 39637506
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
ID: 39642171
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
ID: 39644507
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
ID: 39654711
Looking at this again today>
0
 

Author Closing Comment

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

Featured Post

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

707 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