redirect to javascript function

Discussion in 'JavaScript' started by gilgalbiblewheel, May 27, 2009.

  1. #1
    Is there a way to redirect a page to a JavaScript function:
    <?php
    if($_GET["goto"]!==""){
    	echo $_GET["goto"];
    	echo "<input name=\"\" id=\"gotolink\"type=\"hidden\" value=\"".$_GET["goto"]."\" />\n";
    	//header("Location: index.php");
    	echo "<meta http-equiv='Refresh' content='0; url= \"JavaScript: gotolink();\"' />\n";
    	//echo "<meta http-equiv='Refresh' content='0; url= ../index.php' />\n";
    }
    
    ?>
    PHP:
    The point of this is let's say the url is this:
    http://mywebsite.com/flashclips/hockey.php?goto=flashclips/hockey.php

    I want the goto to be grabbed by the get method redirect to the index and using AJAX I want this extension:
    goto=flashclips/hockey.php

    to be appearing in the "main" div tag.
    
    function createRequest(){
    	var req = false;
    	try {
    		req = new ActiveXObject('Msxml2.XMLHTTP');
    	} catch (e2) {
    	try {
    		req = new ActiveXObject('Microsoft.XMLHTTP');
    	} catch (e3) {
    		try {
    			req = new XMLHttpRequest();
    		} catch (e1) {
    			req = false;
    			}
    		}
    	}
    	return req;
    }
    
    /*****************************************************************/
    function getit(aid, aurl){
    	var req = createRequest();
    	if(req){
    		req.onreadystatechange = function(){
    			var c = document.getElementById(aid);
    			if(req.readyState){
    				if(req.readyState == 4){
    					if(req.status == 200){
    						c.innerHTML = req.responseText;
    					}
    				}
    			}
    		}
    	req.open('GET', aurl, true);
    	req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	req.send(null);
    	}
    }
    function gotolink(){
           getit('maindiv','flashclips/hockey.php');
    	location.href = "../index.php";
    }
    
    Code (markup):
     
    gilgalbiblewheel, May 27, 2009 IP