1

I am new to JavaScript and I am trying to implement it into a website like this.

A person wants to download a file. They click on a link, which takes them to another HTML file with the download link, a keyword, and an advertisement.
So they would be on

http://website.com/randompage

And they would click on a link to download a file which would take them to

http://website.com/download.html?keyword=text?file_url=http://website.com/file.txt

If website.com/download.html could accept 2 parameters into an embedded JavaScript (or a seperate file, whichever works better). Then the download.html would show a link to download the file at variable file_url and would display the keyword from variable keyword. Then an ad would be displayed according to the keyword (my ad service does that for me).

Is this possible to do? I would like a sample script, if possible. The ad code can be left out (I already have that part).

Timtech
  • 1,224
  • 2
  • 19
  • 30

1 Answers1

2
<!DOCTYPE html>
<html>
<body>
  hi
  <script>
    function getParam(paramName){
  var prmstr = window.location.search.substr(1);
  var prmarr = prmstr.split ("&");
  var params = {};

  for ( var i = 0; i < prmarr.length; i++) {
     var tmparr = prmarr[i].split("=");
     params[tmparr[0]] = tmparr[1];
  }
  return params[paramName];
}

    document.write('File url: ' +getParam('file_url')+ 
    '<br/>File name: ' +getParam('file_name')+ 
    '<br/>Keyword: ' +getParam('keyword'));
  </script>
</body>  
</html>