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

N

Nick

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?
 
L

Lasse Reichstein Nielsen

Nick said:
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
 
N

Nick

Lasse said:
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.




<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).
 
L

Lasse Reichstein Nielsen

Nick said:
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
 
N

Nick

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.
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top