473,473 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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
4 1656
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Gnarlodious | last post by:
I want to send a variable to a styleswitching script that will be a function of where the script is in the folder structure. The script will then assemble the stylesheet URL around the variable....
4
by: comcast news | last post by:
at least i think it this is the problem am trying to fix a webpage/javascript that i didn't write www.deltaneutral.com when invoked or any new page from the menu, get the error msg line 2...
6
by: paul | last post by:
HI! How do we send a variable from an Iframe page back to its parent? I have a script that calculates the iframe's window size but I need to know how to send that value back to its parent so I...
5
by: Daz | last post by:
Hi everyone. Another simple question which should hopefully warrent a simple answer. I would like a function to be run whenever a variable is updated. I have tried binding the onchange event...
2
by: Owen.Leibman | last post by:
Here is a complete web page: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"> <html> <head> <title>Javascript Embed and onunload</title> <script type="text/javascript"> function useplayer() {...
6
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); ...
1
pbmods
by: pbmods | last post by:
VARIABLE SCOPE IN JAVASCRIPT LEVEL: BEGINNER/INTERMEDIATE (INTERMEDIATE STUFF IN ) PREREQS: VARIABLES First off, what the heck is 'scope' (the kind that doesn't help kill the germs that cause...
3
daJunkCollector
by: daJunkCollector | last post by:
I have the html/javascript posted below, I imagine the fix to my problem is something simple that I am overlooking. My script is a little bit of html and javascript, and there is an embedded flash...
2
by: neeebs | last post by:
Hi, I'm not sure if this is a javascript problem per se, but here goes. I have an xsl document with a python function defined within a <script> block. Elsewhere in the xsl file, within a python...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.