Forum Moderators: open

Message Too Old, No Replies

how to make text in a generated page

         

sergiemag

9:06 pm on Nov 23, 2003 (gmt 0)

10+ Year Member



for example if you make a link open an image in a new window or elsewhere, how can you also put text in that window? -thanks, sergie

tedster

11:31 pm on Nov 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Instead of just placing the URI for the image in a new window, you can place the URI for a complete HTML document -- and place the image plus any other elements you wish in that doc: text, objects, forms etc.

Is that what you meant?

sergiemag

12:29 am on Nov 24, 2003 (gmt 0)

10+ Year Member



well, the reason i dont want to do that is because i dont want a whole bunch of files and that will take a lot of time. i want to make it easier by opening the image instead of a file. is there some way you can do it by placing javascript into the [a] tag with the text i want and where i want it?

also, do you know how to make it so that when you click on an image, a tooltip of some sort pops up?

tedster

1:32 am on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, it's kind of one way or the other. If a URI is a bare image, then that's what get's displayed - a bare image. To show anything more you need an HTML document to hold it.

when you click on an image, a tooltip of some sort pops up?

Perhaps you mean when you "hover" over an image? Browsers are not yet consistent with that -- the W3C says a title attribute is what is correct, but you often see browsers display an alt attribute instead. Using both attributes is the safer path for now.

If you really mean "click", then you're talking about DHTML -- not really a langauge of it's own, but a combination of JavaScript and CSS. There are lots of free scripts available on the web for all kinds of DHTML effects.

But one downside for using DHTML is that it can really increase the file size of a single page. For instance, if you wanted an enlargement of an image to appear in a div that was hidden until the user clicked on it, that image would still need to download invisibly whenever the page itself downloaded -- even for visitors who never see it.

Another downside is making DHTML work well across different browsers and operating systems -- it can be a real mind bender. That's why sites with DHTML scripts exist - they have usually pre-solved the compatibility issues for you and say right up front which browsers a script is good for.

Used with caution (that is, not for extremely mission-critical purposes) DHTML can add some spice to a website.

But still, I think the easiest, surest path would be to create the HTML files that pop-up onClick and show image plus text. I do this a LOT and it's very user-friendly on most sites. Also I do not find it painful to keep track of the extra HTML files at all.

DrDoc

3:56 pm on Nov 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can, actually, generate a dynamic page using document.write, or even some server side scripting language (such as Perl/PHP/ASP).

Here's how to do it in JavaScript:


<html>
<head>
<title>Untitled</title>
</head>
<body>
<script type="text/javascript">
function createImgWin(img) {
foobar = window.open()
foobar.document.write("<html><head><title>My dynamic page</title></head><body><img src='"+img+"'><br>Here's my text. It will be displayed for every image I use.<br><br>Neat, eh? :-)</body></html>")
}
</script>
<a href="javascript:createImgWin('http://www.google.com/images/logo.gif')">Test</a>

</body>
</html>