Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

browser independent code to set href please! 1

Status
Not open for further replies.
Jul 13, 2005
47
US
I have an image map, using <map> and <area> tags that I want to 'flip' the URL when somebody clicks a button.

Here is my html
Code:
<map name="myMap"><area name="myMap" shape="rect" coords="11,241,206,257" href="mailto:jo@here.com" alt="mail to jo" title="mail to jo"></map>

The following Javascript works in Mozilla/Firefox:

Code:
window.document.links['myMap'].href='mailto:blootytooty@someplace.com';

I also want to do stuff like set the coords, alt tags, and title. A quick test of these in Mozilla firefox showed that I think it will work. How the heck do you do this in IE?????

strong mind, strong body and vice versa
 
ok - you rock!-thank you it was truly amazing how fast that response was.

I knew it was something fairly simple.

un cosa mas:

Can you please give me an example of how you print values to the screen in JavaScript for debugging:

I've tried
Code:
document.write(getElementByID('myMap').href); 
window.alert(getElementByID('myMap').href);

and a few other permutations, but none of my attempts seem to work.



pain makes man think. thought makes man wise. wisdom makes life endurable
 
getElementByID should be getElementByI[red]d[/red].

document.write won't always work (only if the page is still rendering). alert should work all the time.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
OK thanks for the correction on the "d"

this doesn't work:

window.alert(getElementById('myMapp').href);

pain makes man think. thought makes man wise. wisdom makes life endurable
 
should be

Code:
alert(document.getElementById('myMapp').href);

assuming you've given your element an id of "myMapp" (case sensitive) and you're calling the code correctly. if this doesn't work please show related HTML and JavaScript.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
sorry, that should have been:

OK thanks for the correction on the "d"

this doesn't work:

window.alert(getElementById('myMap').href);


pain makes man think. thought makes man wise. wisdom makes life endurable
 
OK, let's start over:

here is the html

Code:
<map name="myMap"><area id="myAreaMap" name="myMap" shape="rect" coords="11,241,206,257" href="mailto:jo@somewhere.com" alt="mail to jo" title="mail jo"></map>

here is the javascript that now, works fine:
Code:
document.getElementById('myAreaMap').href = 'mailto:blootytooty@someplace.com';

This does not work, yet when present does not stop the other code from working.
Code:
window.alert(getElementById('myAreaMap').href);


pain makes man think. thought makes man wise. wisdom makes life endurable
 
because, clearly, I am a dingbat. It works

cheers. and thanks once again

pain makes man think. thought makes man wise. wisdom makes life endurable
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top