Use of <a href> tag

C

Chas

Hello:

This link, <a href="images/Recruit.jpg"> Picture of Recruit </a> will
display a photo in a new browser window. Is it possible to set the
background color in the new browser window? Thanks.

Charlie
 
T

Trevor Lawrence

Try
<a href="recruit.html"> Picture of Recruit </a>

where recruit.html is
<html>
<head>
<!-- other head stuff in here -->

<style type="text/css">
body {background-color:red;}
</style>
</head>

<body>
..<!-- other body stuff in here -->

<img src="images/Recruit.jpg">

..<!-- other body stuff in here -->
</body>
</html>
 
C

Chas

Hello Trevor:

Thank you for the reply. That is a solution I may have to use. I have many
of these pictures I have to link and was hoping I didn't have to create an
html page for each picture. Thanks again.

Charlie
 
M

Mike Mueller

The answer given to you is based 100% on the question you asked

If you want to have recruit.html be a generic page for different images then
you will need to use some scripting, either server or client side would be
fine.

Generic ASP version

<a href="Recruit.asp?id=Recruit1.jpg">Recruit1</a>

Recruit.asp

<% urlImage = Trim(" " & Request.QueryString("id")) %>
<html>
<head>
<!-- other head stuff in here -->
<style type="text/css">
body {background-color:red;}
</style>
</head>
<body>
<!-- other body stuff in here -->
<% IF urlImage <>"" THEN %>
<img src="images/<%=urlImage%>" />
<% ELSE %>
<!-- whatever content you want to display in case of error -->
<% END IF %>
<!-- other body stuff in here -->
</body>
</html>
 
T

Trevor Lawrence

MIke,

I agree 100%. In fact, I have a website with a generic page for images
(named picture.html, but that is irrelevant). I put images into this page
using client side Javascript. Works for me !

Chas,
Do you want me to post he Javascipt
 
C

Chas

Hello Trevor/Mike:

Thank you both for the replies. Trevor, I would appreciate if you would
post the Javascript. Thanks.

Chas
 
T

Trevor Lawrence

Chas,

I realise that my original code has grown a bit and is now rather complex.

I'll see if I can trim it down to the simplest code similar to what Mike has
done with ASP, and get back to you
 
M

Mike Mueller

One other thing that is nice about using javascript is that you can do
popups with it
A nice thing about using a page for the images is that you can do more than
a background color- on this gallery from a few years back I took the site
color scheme and made a picture frame for the popup image.
http://lgp296.org/Gallery/SunbeamTea2007.aspx
 
T

Trevor Lawrence

Mike,
I'll have a look at your page.

Without looking at it, I think what I do may be similar. I do a popup using
window.open('picture.html'). In picture.html, I use JS to determine the
image size and use this to position the window centrally and size it (the
window) to fit the image. This is at http://tandcl.homemail.com.au/ Click on
either picture on left or right (me or Carole). I actually use the image as
a background image overlaid on a table with rounded corner images in the
cells

However, this is too complex for Chas' simple query. This is why I didn't
post yesterday

Chas, here is the simplified code

This is the calling page
<html>
<head>
<title>Test Picture</title>
</head>
<body>
<a href="picture.html?p=images/test image.jpg&c=A test caption">
A test image</a>
</body>
</html>

This is picture .html
<html>
<head>
<title>Picture</title>
<!-- other head stuff in here -->
<script type="text/javascript">
function qsobj(parm) {
var qpairs, qvbl;

// get url string after '?' and split by "&" into an array
qpairs = location.search.substring(1).split("&");

// if qpairs[parm] exists, split by "=" into an array, else return null
if (qpairs[parm]) qvbl = qpairs[parm].split("=");
else return null;

// return string after "=" if it exists, else null
return qvbl[1] ? unescape(qvbl[1].replace(/%20|\ +/g," ")) : null;
} // ---- end qsobj() ------------

function getPic() {
document.getElementById("pic").src=qsobj(0);
document.title =
document.getElementById("pic").title =
document.getElementById("cap").value = qsobj(1)||qsobj(0);
} // ---- end qetPic() ------------
</script>

<style type="text/css">
body {background-color:red;}
div {text-align: center; }
</style>
</head>

<body onload="getPic()">
<!-- other body stuff in here -->

<div>
<img id="pic"><br>
<input id="cap" type="text">
</div>

</body>
</html>

The CSS in picture.html sets a red background and centres the <div> in which
the image is placed. You can change these to suit.

I also added code to place a caption underneath the image, in the <img>
title (when the image is moused over) and in the document title (in the
title bar). This is optional. It can be omitted by using <a
href="picture.html?p=images/test image.jpg"> in which case the image
filename will be used.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top