tags:

views:

50

answers:

2

I'm trying to figure out the correct syntax for this. How can I modify

('<a href="http://www.link.com" target="_blank">name here</a>')

accordingly so it can accept an image instead of text? Here's my script:

s = new slide();
s.src = '0001Work.jpg';
s.text = unescape('1%20of%2012');
s.textb = unescape('<a href="http://www.link.com" target="_blank">name here</a>');
slides.add_slide(s);
A: 

You may want to rephrase your question, as "accept an image" doesn't mean anything specific.

I can think of three things you might mean:

  1. The caller of the function passes in the URL of an image, and wants that image to be rendered instead of a hyperlink. In which case you could just set:

    s.textb = unescape('<img src="' + imgParameter + '"></img>');

  2. The caller passes in the URL of an image to use as the contents of the hyperlink. In which case you'd basically put the above unescaped code between the existing anchor tags:

    s.textb = unescape('<a href="http://www.link.com" target="_blank"><img src="' + imgParameter + '"></img></a>');

  3. One of the above options but taking a Javascript Image object instead of the URL; in which case, you extract the URL from the image via image.src and then proceed with one of the above options.

If none of these cover your case, then please clarify what you meant, perhaps with a pseudocode example. Don't forget to say what the expected output is rather than "it doesn't work". :-)

Andrzej Doyle
Hey thanks for helping out! I agree with the rephrase, you suggestion made a lot more sense. Keep you posted on the outcome.
deto
A: 

Your question does not make much sense. Is this what you want?

var anchor = document.createElement("a");
var image = document.createElement("img");

image.src = "0001Work.jpg";
image.alt = "A picture";

anchor.href = "http://example.com/";
anchor.appendChild(image);

document.appendChild(anchor);
jsumners
Will try this technique and let you know, thanks for helping out
deto