heldplayer Posted October 27, 2009 Share Posted October 27, 2009 I am making an imageviewer that loads an image throug the window.location.search but when the image is loaded I get an alert that says:Stack overflow at line: 0window.location.search is ?img=210&year=2007-2008&type=big function getImage(){var img=window.location.search.substr(1).split("&");var img=image[0].split("=")[1];var year=image[1].split("=")[1];var type=image[2].split("=")[1];var src="../" + year + "/" + type + "/" + img + ".bmp";return src;} the .bmp is because 1: its curently in my pcand 2: jpg, gif, ... doesn't work Link to comment Share on other sites More sharing options...
justsomeguy Posted October 27, 2009 Share Posted October 27, 2009 What are you doing with the return value of that function? Link to comment Share on other sites More sharing options...
jeffman Posted October 27, 2009 Share Posted October 27, 2009 var img=window.location.search.substr(1).split("&");var img=image[0].split("=")[1];Should be the same object, yes? Link to comment Share on other sites More sharing options...
heldplayer Posted October 27, 2009 Author Share Posted October 27, 2009 img and image are not the same,the return value is for setting the <img /> src valuebut the problem is solved, I called the function within the image but if it is in the body then it is ok:bad: <img onload="this.src=getImage()" />good: <body onload="document.getElementById('image').src=getImage()"> Link to comment Share on other sites More sharing options...
Ingolme Posted October 27, 2009 Share Posted October 27, 2009 You're also declaring the same variable twice, which isn't a good thing:var img=window.location.search.substr(1).split("&");var img=image[0].split("=")[1]; Link to comment Share on other sites More sharing options...
justsomeguy Posted October 27, 2009 Share Posted October 27, 2009 bad: <img onload="this.src=getImage()" />Oh, right. Every time you set the source it's going to load the image and set the source again, which is going to load the image and set the source, again. Link to comment Share on other sites More sharing options...
heldplayer Posted October 28, 2009 Author Share Posted October 28, 2009 You're also declaring the same variable twice, which isn't a good thing:var img=window.location.search.substr(1).split("&");var img=image[0].split("=")[1];misspelled it, the first img should be image, sorry Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.