+ Reply to Thread
Results 1 to 3 of 3

Thread: Explain A Javasript

  1. #1
    espfutbol98's Avatar
    espfutbol98 is offline x10 Sophmore espfutbol98 is an unknown quantity at this point
    Join Date
    Apr 2009
    Location
    Zagreb... želim
    Posts
    200

    Explain A Javasript

    Could someone please inform me on how this script I found works. I found it on a login page that pops-up and once authenticated, closes and refreshes the page. I'm not sure exactly what it says or how to change it to not use ?sec or &sec but rather just normal page names.
    Code:
    <script language="javascript"> 
    	     function CloseAndReturn(sectionID){
    	       if (window.opener)
    	        {
    	        var url=window.opener.location.href;
    	        if (url.indexOf("sec=")>-1) 
    	        {
    	            var firstpart;
    	            var middlepart;
    	            var lastpart="";
    	            firstpart=url.substring(0,url.indexOf("sec="));
    	            middlepart=url.substring(url.indexOf("sec="));
    	       	if (middlepart.indexOf("&")>-1)
    	            lastpart=middlepart.substring(middlepart.indexOf("&"));
    	            window.opener.location.href=firstpart + "sec=" + sectionID + lastpart;
    	        }  
    	        else  
    	        {
    	            if (url.indexOf("?")==-1)
    	                window.opener.location.href=url + "?sec=" + sectionID;
    	            else
    	                window.opener.location.href=url + "&sec=" + sectionID;
    	        }
    	        window.close();
    	        }
    	     }
    	   </script>

  2. #2
    garrettroyce's Avatar
    garrettroyce is offline Generally Helpful Member garrettroyce is a glorious beacon of lightgarrettroyce is a glorious beacon of light
    Join Date
    Apr 2008
    Location
    IL, USA
    Posts
    3,746

    Re: Explain A Javasript

    Code:
    <script language="javascript">
         function CloseAndReturn(sectionID){
              if (window.opener) // if the background window is still open, continue
              {
                   var url=window.opener.location.href; // url of the background window
                   if (url.indexOf("sec=")>-1) // if the background url contains "sec"
                   {
    	            var firstpart;
    	            var middlepart;
    	            var lastpart="";
    	            firstpart=url.substring(0,url.indexOf("sec=")); // everything before "sec"
    	            middlepart=url.substring(url.indexOf("sec=")); // everything including and after "sec"
                        if (middlepart.indexOf("&")>-1) // if there is "&" in middlepart
    	            lastpart=middlepart.substring(middlepart.indexOf("&")); // lastpart is everything including and after "&"
    	            window.opener.location.href=firstpart + "sec=" + sectionID + lastpart; //sets the new url for the background page
                   }  
                   else  // "sec" is not in the URL, make a new URL with it
                   {
                        if (url.indexOf("?")==-1) // if there is no query string
    	                window.opener.location.href=url + "?sec=" + sectionID; // add query string "?sec=..."
    	            else // if there is a query string
    	                window.opener.location.href=url + "&sec=" + sectionID; // add query string "sec=..."
    	        }
    	        window.close(); // close this window
    	        }
    	     }
    	   </script>
    I hope that helps
    gjr.gr - coming soon: secrets of OCD coding from a self taught tinkerer

  3. #3
    Twinkie is offline Banned Twinkie is an unknown quantity at this point
    Join Date
    Sep 2007
    Location
    Ft. Lauderdale, Florida
    Posts
    1,389

    Re: Explain A Javasript

    You should really just use a normal form, or AJAX if you want to be fancy. Popup windows distract the user, distract the user, and make them think "why is that there" rather than focusing on the site.

+ Reply to Thread

Similar Threads

  1. SQL EXPLAIN DON't WORK
    By batman1 in forum Programming Help
    Replies: 3
    Last Post: 04-21-2009, 05:47 PM
  2. explain please
    By galaxyAbstractor in forum Programming Help
    Replies: 4
    Last Post: 02-16-2009, 09:26 AM
  3. Replies: 1
    Last Post: 08-10-2008, 10:03 PM
  4. Please explain this installation of ASP in Apache2triad...
    By anuj_web in forum Scripts & 3rd Party Apps
    Replies: 0
    Last Post: 06-13-2008, 05:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers