Sunday, 15 March 2015

javascript - script runs only after refresh! any ideas? -



javascript - script runs only after refresh! any ideas? -

i have page images. when clicks @ image want open page , shows image clicked. seems script runs after refresh!

<body> <img src="whatimg()" id="image"/>

// , here script

function whatimg(){ var str = geturlvars()["obj"]; document.getelementbyid('image').src = str;} function geturlvars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m, key, value) {vars[key] = value;}); homecoming vars; } whatimg(); </script> </body>

what you'll want alter src attribute within script.

<!doctype html> <html> <head> <title></title> </head> <body> <img src="blank.gif" id="image"/> <script> function whatimg(){ var str = geturlvars()["obj"]; document.getelementbyid('image').src = str; } function geturlvars() { var vars = {}; var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi,function(m, key, value) {vars[key] = value;}); homecoming vars; } whatimg(); </script> </body> </html>

javascript jquery html

No comments:

Post a Comment