How to change an image according to the url parameter.
example: I want this url to show the image link and in another url such as link does not appear. being the main page is unique and only the search parameter that changes.
CSS
This line of CSS to hide the div that contains the image, because JavaScript will be used to show the contents of this div when desired.
.minhaDiv {
display:none;
}
The Script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><scripttype="text/javascript">
// Analise o parâmetro do URL
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, " "));
}
// obtem o parametro fq
var dynamicContent = getParameterByName('fq');
$(document).ready(function() {
// Checa se o parametro é H:321
if (dynamicContent == 'H:321') {
$('#mostra').show();
}
});
</script>
HTML
<div id="mostra" class="minhaDiv">
<img src="Sua_Imagem.ext">
</div>
Examples:
strong>