javascript - Change the src of an image when the page loads -


i trying change src of image , once changed remain on whole website.

<img id="profile" src="profilepicture.jpg"> <input type="text" name="image" id="imglink"> <button type="button" id="upload">upload</button> 

jquery:

$(document).ready(function () {      var link;     $("#upload").click(function (){         link = $("#imglink").val();         $("#profile").prop('src', link);     });     $("#profile").prop('src', link);      }); 

as can see tried store link of image in global variable( var link ) , change src of image inside function , change once again outside page loads image when it's loaded.

changing src of image works once refresh page or go page , come back, image not changed more.

how can make remain changed on whole website?

normally on serverside since clientside solution works on 1 browser user using.

$(function () {      //read localstorage     var link = localstorage.getitem("myimage") || ""; //change "" default value     $("#upload").click(function (){         link = $("#imglink").val();         $("#profile").prop('src', link);         localstorage.setitem("myimage", link); //set localstorage new value.      });     $("#profile").prop('src', link);    }); 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -