I'm a newbie to HTML. I googled the question and tried some code but it didn't work so I'm asking here for help.
What I am trying to achieve: replacing the ?? in the HTML paragraph with a value from a URL (for example: http://mysite.html?name=Ryan)
<p> Hello ??<br> Thanks for answering my question</p>
My Questions: 1. This Javascript should extract Ryan from the URL - is it correct?
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script type="text/javascript">
// Parse the URL parameter
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
// Give the parameter a variable name
var urlVar = getParameterByName('name');
});
</script>
- If the code in Question 1 is correct, how do I place the value in
urlVar
(which is Ryan) instead of the ?? inside the HTML paragraph?