-5

Maybe just a basic question because Im new on Jquery.

I try to find any way to get data from url or called as url get parameter

Example= mysite.com/go.html?link=data Then I found this code on this forum but I confused how to use it on my html page.

    function getParameterByName(name)
{
  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
  var regexS = "[\\?&]" + name + "=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.search);
  if(results == null)
    return "";
  else
    return decodeURIComponent(results[1].replace(/\+/g, " "));
}

How to use it? For example the url that I d=visit is mysite.com/go.html?link=example.com and I want to show the example.com in <a href="example.com"> on my html page

1 Answers1

0

First off, this isn't "jQuery" code, it's Javascript code. In short, the way to implement the code you are asking about is as follows:

function displayLink(){
var link = getParameterByName("link");
var container = document.getElementById("myContainer");
container.innerHTML = "<a href="'+link+'">Click here for link</a>";
}

Where "myContainer" is the ID of the element where you want to link to appear in your page. Then, you can call the "displayLink" function when the page is loaded and the link will be added. This is an extremely simplified method of implementing what you asked for (although it will get the job done), and I recommend, as was said in the comments, that you learn basic Javascript before attempting to add code into your web page.

Eyal
  • 532
  • 2
  • 12