Created
September 11, 2020 18:08
-
-
Save dvygolov/7b1d5a85e1ce1bdf9fc95fd631801702 to your computer and use it in GitHub Desktop.
Скрипт для динамической замены основной картинки на прелендинге. Подключать как: <script src="changepic.js"></script>. Картинки загрузить в папку images. Основной картинке присвоить id="mainpic".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener('DOMContentLoaded', function(){ | |
var pName='mainpic'; | |
var pic = document.getElementById(pName); | |
var urlParams = new URLSearchParams(window.location.search); | |
if (urlParams.has(pName)){ | |
var pValue = urlParams.get(pName); | |
pic.src = 'images/'+pValue+'.jpg'; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Далее юзать как http://your.domain?mainpic=2. При этом в папке images должна быть картинка 2.jpg