By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,259 Members | 1,708 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,259 IT Pros & Developers. It's quick & easy.

Any variable in embedded javascript to reference the object embedsthe script?

P: n/a
For example, I have the following code:

<img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
<map name="photo_ring_r1_c1">
<area shape="circle" coords="30,30,30"
href="javascript:show_details('ring1');" alt="ring1" title="ring1">
</map>

Is it possible to modify the

href="javascript:show_details('ring1');"

to something like

href="javascript:show_details(embeddedObject.tags. alt);"

So the 'alt' of area shape will be the parameter of teh show_details
function?

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Nick <nb**********@hotmail.com> writes:
For example, I have the following code:

<img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
<map name="photo_ring_r1_c1">
<area shape="circle" coords="30,30,30"
href="javascript:show_details('ring1');" alt="ring1" title="ring1">
</map>

Is it possible to modify the

href="javascript:show_details('ring1');"

to something like

href="javascript:show_details(embeddedObject.tags. alt);"
Yes. First of all, you should not use a "javascript:"-URL. For several
reasons <URL:http://jibbering.com/faq/index.html#FAQ4_24>.
Instead, use the onclick attribute.

You should also use the title attribute appropriately. It should contain
information that further describes the element. The alt attribute
should be used for information that is shown when the browser can't
show the area graphically (e.g., a text browser). They are not the same,
and should be used differently.
So the 'alt' of area shape will be the parameter of teh show_details
function?


<area shape="circle" coords="30,30,30"
href="thisLinkNeedsJS.html" alt="Foobar" title="Information about Foobar"
onclick="show_details(this.alt);">

The href should point to a page that explains that your page requires
Javascript to function correctly (and why, if you can defend it).
A signifiacnt number of people browse with Javascript turned off
or not available.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

P: n/a
Lasse Reichstein Nielsen wrote:
Nick <nb**********@hotmail.com> writes:

For example, I have the following code:

<img src="photo_ring_r1_c1.jpg" title="" alt="Rings"
style="width: 200px; height: 150px;" usemap="#photo_ring_r1_c1">
<map name="photo_ring_r1_c1">
<area shape="circle" coords="30,30,30"
href="javascript:show_details('ring1');" alt="ring1" title="ring1">
</map>

Is it possible to modify the

href="javascript:show_details('ring1');"

to something like

href="javascript:show_details(embeddedObject.tag s.alt);"

Yes. First of all, you should not use a "javascript:"-URL. For several
reasons <URL:http://jibbering.com/faq/index.html#FAQ4_24>.
Instead, use the onclick attribute.

You should also use the title attribute appropriately. It should contain
information that further describes the element. The alt attribute
should be used for information that is shown when the browser can't
show the area graphically (e.g., a text browser). They are not the same,
and should be used differently.

So the 'alt' of area shape will be the parameter of teh show_details
function?

<area shape="circle" coords="30,30,30"
href="thisLinkNeedsJS.html" alt="Foobar" title="Information about Foobar"
onclick="show_details(this.alt);">

The href should point to a page that explains that your page requires
Javascript to function correctly (and why, if you can defend it).
A signifiacnt number of people browse with Javascript turned off
or not available.

/L


I am using javascript to open a popup window. It can also be done using
onclick. However, I don't want the main page go to any url. And the
dreamweaver use href="#" and it really annoy because the page always
scroll to the beginning of the hmtl after click the map (and it will
always go to the URL of href if putting any URL there).

Currently I am using

href="javascript:;" to void the page scrolling to beginning.

And I also found that href="javascript:showPopup(this.alt)" doesn't
work. but onclick="javascript:showPopup(this.alt)" works well.
Interesting.... (I tested it on IE 6).
Jul 20 '05 #3

P: n/a
Nick <nb**********@hotmail.com> writes:
I am using javascript to open a popup window.
Dangerous.
It can also be done using onclick. However, I don't want the main
page go to any url.
In that case, do as the FAQ says, not as I say :)
Because I forgot to add the "return false" at the end of the onclick
handler which would prevent the normal operation of the link.
And the dreamweaver use href="#"
Bad idea. Even href="" is better, but neither are the slightest bit
useful to someone with no Javascript.
and it really annoy because the page always scroll to the beginning
of the hmtl after click the map (and it will always go to the URL of
href if putting any URL there).
unless you return false, i.e.,
onclick="show_details(this.alt);return false;"
Currently I am using

href="javascript:;" to void the page scrolling to beginning.
Worse, for all the reasons in the FAQ.
And I also found that href="javascript:showPopup(this.alt)" doesn't
work. but onclick="javascript:showPopup(this.alt)" works
well. Interesting.... (I tested it on IE 6).


That is because the javascript in the first is executed in the global
scope (just as if you typed it in the address line), so "this" refers
to the global object. The second is executed as a property of the
element, so "this" refers to the element.

You don't need "javascript:" in front of onclick handlers!
By coincidence, it is not a syntax error, but it doesn't do anything.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4

P: n/a
Thanks very much. I've changed according to your suggestions. However,
for the browsers without javascript(or dissabled). Currently it seems
javascript is so widely used and some tools like VisualStudio.Net's
ASP.Net development environment even automatically generate javascript
when dragging the component to the web page. I guess some JSP
development tools do the same too.

So hopefully, Javascript is automatically supported by most end-users'
browser.
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.