Reputation: 6088
I have a simple application and the JS code looks like this:
function refresh(){
window.location.reload();
document.getElementById("a").src="http://30.media.tumblr.com/tumblr_l8nftqa6oF1qbadnxo1_500.png";
}
The button HTML code is:
<button id="refresh" onclick="refresh()">Refresh</button>
And the HTML code where the src
should go looks like this:
<img id="a" style="position:absolute;top:390px;left:15px;height:254px;width:330px">
The rest of the code that has an input type text
goes okay but the image never gets loaded properly and I have tried couple of things, but I am new to JS so don't know how to do this properly.
Upvotes: 0
Views: 131
Reputation: 831
You might not need to reload the page at all. On the button click, you could just get the new image as follows. In short, get rid of "window.location.reload()" if you don't need it
`function refresh(){
document.getElementById("a").src="http://ecx.images-amazon.com/images/I/3131FYr6f6L._SL500_AA300_.jpg"; }`
(Note that I changed the image path because I was getting an "access denied" on the one you had in your post.)
Upvotes: 0
Reputation: 4682
You would like to use this code:
function refresh(){
window.location.reload();
}
window.onload = function () {
document.getElementById("a").src="http://30.media.tumblr.com/tumblr_l8nftqa6oF1qbadnxo1_500.png";
}
Upvotes: 1