Team:Heidelberg LSL/Check out

From 2012hs.igem.org

(Difference between revisions)
Line 9: Line 9:
</style>
</style>
 +
function getValue(varname)
 +
{
 +
  // First, we load the URL into a variable
 +
  var url = window.location.href;
 +
 +
  // Next, split the url by the ?
 +
  var qparts = url.split("?");
 +
 +
  // Check that there is a querystring, return "" if not
 +
  if (qparts.length == 0)
 +
  {
 +
    return "";
 +
  }
 +
 +
  // Then find the querystring, everything after the ?
 +
  var query = qparts[1];
 +
 +
  // Split the query string into variables (separates by &s)
 +
  var vars = query.split("&");
 +
 +
  // Initialize the value with "" as default
 +
  var value = "";
 +
 +
  // Iterate through vars, checking each one for varname
 +
  for (i=0;i<vars.length;i++)
 +
  {
 +
    // Split the variable by =, which splits name and value
 +
    var parts = vars[i].split("=");
 +
   
 +
    // Check if the correct variable
 +
    if (parts[0] == varname)
 +
    {
 +
      // Load value into variable
 +
      value = parts[1];
 +
 +
      // End the loop
 +
      break;
 +
    }
 +
  }
 +
 
 +
  // Convert escape code
 +
  value = unescape(value);
 +
 +
  // Convert "+"s to " "s
 +
  value.replace(/\+/g," ");
 +
 +
  // Return the value
 +
  return value;
 +
}
Line 20: Line 69:
<script type="text/javascript">
<script type="text/javascript">
-
document.write($_GET['name']);
+
var name = getValue("name");
 +
document.write(name);
</script>
</script>

Revision as of 12:25, 11 June 2012

iGEM-2012HS - LSL-Heidelberg iGEM-2012HS - LSL-Heidelberg

iGEM-2012HS - LSL-Heidelberg

function getValue(varname) { // First, we load the URL into a variable var url = window.location.href; // Next, split the url by the ? var qparts = url.split("?"); // Check that there is a querystring, return "" if not if (qparts.length == 0) { return ""; } // Then find the querystring, everything after the ? var query = qparts[1]; // Split the query string into variables (separates by &s) var vars = query.split("&"); // Initialize the value with "" as default var value = ""; // Iterate through vars, checking each one for varname for (i=0;i