0

I am trying to make kind of online gallery, this is first .html doc and when I click on one of image thumbnail it should open html with that image full size in gallery.html

<html >
<head>
<title>Untitled Document</title>
</head>
<body > 
<a href="gallery.html?image1.jpg"> <img  height="85" width="85"  src="image1.jpg" /> </a>
<a href="gallery.html?image2.jpg"> <img  height="85" width="85"  src="image2.jpg" /> </a>
<a href="gallery.html?image3.jpg"> <img  height="85" width="85"  src="image3.jpg" /> </a>
</body>
</html>

gallery.html

<html>
<head>
<script language = "javascript">
function getUrl(){
var url = window.location.search;
path = url.substring(1);
changeImage(path);
}

function changeImage(path){
var imgDest = document.getElementById("image");
var imgSrc = path;
imgDest.setAttribute("src", imgSrc);
}
</script>
<title>Galerry</title>
</head>
<body>
<img src="" id="image"/>
<br>
</body>
</html>

all images and .html docs are in same folder... also there are some .jpg images which names has spaces in them, so click on them puts %20 in adrress bar instead of the space, I know that %20 replaces space, but is the problem maybe there? I thought so, but it want load image with regular name too. Any idea how could I load these images?

regards

3
  • are you sure that path = url.substring(1); gets imageX.jpg from the URL? Commented Jun 25, 2012 at 9:27
  • You are not calling getUrl() function... and make sure that 'path' var in getUrl() is getting correct path (you can use an alert there).. Commented Jun 25, 2012 at 9:31
  • yes, path was correct, problem was pretty obvious, I didnt have onload in body :s Commented Jun 25, 2012 at 9:53

1 Answer 1

1

Seems to me that your javascript functions is never called. Edit your script so it is being called on page load:

<script language="javascript">
// Assign an anonymous function to the onload event
window.onload = function(){
    // Place code to execute here.
}
</script>

Or, edit your <body> tag:

  <body onload="getUrl();">
Sign up to request clarification or add additional context in comments.

1 Comment

tnx, that was it, guess I should rest now, not seeing obvious things :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.