Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jan 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts

    redirect with javascript

    Code:
    <HTML>
    <HEAD>
    <TITLE> Homepage of Thomas Blomme </TITLE>
    <META name="Author" lang="en" content="Thomas Blomme">
    <META name="keywords" lang="en" content="homepage, java, netbeans, JDance,linux, gentoo, mysql, php"> 
    <META http-equiv="content-type" content="text/html; charset=UTF-8">
    <META name="date" content="2007-01-20" >
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    
    <SCRIPT language="javascript" src="../functions.js">
    </SCRIPT>
    </HEAD>
    
    <BODY>
    <TABLE height="100%" width="100%">
    <TR align="center">
    
    <TD><IMG src='pictures/language_nl.png' align='middle' onclick="createLink('main.php?lang=nl')"></IMG></TD>
    <TD><IMG src='pictures/language_en.png' align='middle' onclick="createLink('main.php?lang=en')"></IMG></A></TD>
    
    </TR>
    
    <TR align="center">
    <TD height="10%" colspan="2">No javascript? <A href="alt_index.html">yes</A></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>
    I use the code above, to send a link to a javascript function which should make some adjustments to it, add version info, screen size and so on to the url and then redirect to it, at the moment I use the follwing code for that:

    Code:
    var width = screen.width;
    var referrer = document.referrer;
    var agent = navigator.userAgent;
    var version = navigator.appVersion;
    
    function createLink(link)
    {
    	link = createInfo(link);
    	window.location(link);
    }
    
    function createInfo(link)
    {
    	patternMain = /main.php\?/;
    	patternWidth = /width=/;
    	patternReferrer = /referrer=/;
    	patternAgent = /agent=/;
    	patternVersion = /version=/;
    	patternMark = /\?$/;
    	patternMark2 = /&$/;
    	if(link == "main.php")
    	{
    		link = "main.php?width=" + width + "&referrer=" + referrer + "&agent=" +
    		agent + "&version=" + version;
    	}
    	else if(patternMain.test(link))
    	{
    		document.write("main");
    		if(!patternWidth.test(link))
    		{	
    			if(!patternMark.test(link) && !patternMark2.test(link))
    			{	
    				link = link + "&";
    			}
    		link = link + "width=" + width;
    		}
    		if(!patternReferrer.test(link))
    		{
    			if(!patternMark.test(link) && !patternMark2.test(link))
    			{
    				link = link + "&";
    			}
    		link = link + "referrer=" + referrer;
    		}
    
    		if(!patternAgent.test(link))
    		{
    			if(!patternMark.test(link) && !patternMark2.test(link))
    			{
    				link = link + "&";
    			}
    		link = link + "agent=" + agent;
    		}
    
    		if(!patternVersion.test(link))
    		{
    			if(!patternMark.test(link) && !patternMark2.test(link))
    			{
    				link = link + "&";
    			}
    		link = link + "version=" + version;
    		}
    	}
    	return link;
    }

    this seems however to redirect to the same page as before and not to main.php

    I have added a line of code to main.php, which I should see when the url is correctly submitted:

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    	"http://www.w3.org/TR/html4/loose.dtd">
    <HTML>
    
    <HEAD>
    <TITLE>Homepage of Thomas Blomme</TITLE>
    <META name="Author" lang="en" content="Thomas Blomme">
    <META name="keywords" lang="en" content="homepage, java, netbeans, JDance,linux, gentoo, mysql, php"> 
    <META http-equiv="content-type" content="text/html; charset=UTF-8">
    <META name="date" content="2007-01-20" >
    </HEAD>
    
    <BODY>
    <?php
    echo "referrer=$referrer";
    ?>
    </BODY>
    
    </HTML>
    to see the results: blommethomas.downfire.com

  • #2
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,830
    Thanks
    21
    Thanked 157 Times in 148 Posts
    what's the purpose of this line in your JS:
    document.write("main");
    That could cause some issues....I would remove the line...

    Edit: And the syntax for window.location is:

    window.location="yoururl.com"
    Last edited by chump2877; 02-03-2007 at 10:42 AM.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :-)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!
    ♪♪ …Need Web Hosting For My YouTube-To-Mp3 Conversion Software? Check Here !!… ♪♪

  • #3
    New Coder
    Join Date
    Jan 2007
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks, that solved it,

    such a stupid syntax error, I hate myself :P


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •