URL catcher

Discussion in 'HTML & Website Design' started by metalx1000, Feb 20, 2007.

  1. #1
    Hello,

    I'm new to JavaScripting and have a question that should be simple (I think).

    I want a frame that stays constant and checks the URL of a second frame constantly. When ever the URL of frame2 changes frame one catches the new URL and saves it to a VAR.

    I think that is should be possible and I think that Javascript would be a good way of doing this. Please let me know if this is possible or if Javascript would not be the best route.

    Thanks
     
    metalx1000, Feb 20, 2007 IP
  2. Aragorn

    Aragorn Peon

    Messages:
    1,491
    Likes Received:
    72
    Best Answers:
    1
    Trophy Points:
    0
    #2
    I don't think Javascript allows a frame to access the content of another frame, unless both are from the same domain.

    This should work if they are from the same domain.
    
    // Set this to false, if you want only unique URLs to be added to the var
    var uniqueURL = true;
    
    var arURL = new Array();
    var lastURL = '', curURL = '';
    function storeURL(){
    	//In case this doesn't work, replace frames[1] with frames["second_frame_name"]
    	curURL = window.parent.frames[1].location.href;
    	if(curURL != lastURL){
    		var isUnique = true;
    		if(uniqueURL){
    			for(var i in arURL){
    				if(arURL[i] == curURL){
    					isUnique = false;
    					break;
    				}
    			}
    		}
    		if(isUnique){
    			lastURL = curURL;
    			arURL[arURL.length] = lastURL;
    			alert(arURL);
    		}
    	}
    	setTimeout('storeURL()', 1000);
    }
    
    PHP:
    Call this function on the onload event of your first frame.
     
    Aragorn, Feb 21, 2007 IP