Code snippets – redirecting you webpage


Impetus for this post was that I was helping out a friend on twitter and they needed to do exactly this. So here is how to put code in a page to redirect a browser to another page.

The page you are putting the code into may start with a tag or just a tag (you should have a doctype declaration in there, but that’s a different topic). There are two ways of doing this. The first uses a tag and this usually resides just below the head tag in the section of the document.

<meta http-equiv=”refresh” CONTENT=”0,http://www.einstein.yu.edu/centers/cancer/”>

This says when parsing this page, refresh the page with a 0 second delay and render the URL I designate.

The second way uses a javascript and the first part of this is the script itself (originally generated by dreamweaver) and is as follows it goes in the section of the html document just before the end of the head tag:

The script (originally generated by dreamweaver) is as follows and goes in the section of the html document just before the end of the head tag:

<script language=”JavaScript”>
<!–
function MM_goToURL() { //v3.0
var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
for (i=0; i<(args.length-1); i+=2) eval(args[i]+”.location='”+args[i+1]+”‘”);
}
//–>
</script>

The body tag should contain the following in order for the javascript to do anything:

<body bgcolor=”#FFFFFF” text=”#000000″ onLoad=”MM_goToURL(‘parent’,’http://www.einstein.yu.edu/centers/cancer/’);return document.MM_returnValue”>

Leave a comment

Your email address will not be published. Required fields are marked *