473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

invoke link click event in Navigator

I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.

I need to be able to do the same in Netscape Navigator,

can anyone help ?

Jul 23 '05 #1
21 6521
news.btinternnet.com wrote:
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.
if ( myLink.href ) document.location.href = myLink.href;

I need to be able to do the same in Netscape Navigator,


My install of Navigator is broken, I'm about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)

--
Rob
Jul 23 '05 #2
RobG wrote:
news.btinternnet.com wrote:
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on
the link themselves.

if ( myLink.href ) document.location.href = myLink.href;

I need to be able to do the same in Netscape Navigator,

My install of Navigator is broken, I'm about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)


Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can't follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS 'enhanced' version.
--
Rob
Jul 23 '05 #3
Thanks for your help, unfortunately, this was not quite what I was looking
for, perhaps I should have been more specific. I am trying to invoke the
mail helper for the MailTo link. Using the link's click event does this for
IE and NN, but I can invoke the event on NN. I need to construct the
MailTo: using Javascript so I can customise the outgoing mail message.

I know there are other ways of doing this using a form and a bit of CGI
script or whatever, but prefer this method. I know you may say reach is an
issue because not everyon has helpers on their browser, in any case this is
what I am trying to acheive.

Do you know how to invoke the click event programatically in Javascript (
NN ), I would dearly like to know the answer to that ?

Best Regards

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:Ft*****************@news.optus.net.au...
RobG wrote:
news.btinternnet.com wrote:
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.

if ( myLink.href ) document.location.href = myLink.href;

I need to be able to do the same in Netscape Navigator,

My install of Navigator is broken, I'm about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)


Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can't follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS 'enhanced' version.
--
Rob

Jul 23 '05 #4
Sorry this

IE and NN, but I can invoke the event on NN. I need to construct the
MailTo: using Javascript so I can customise the outgoing mail message.

should have said

IE and NN, but I CANT seem to discover how to invoke the event on NN
programatically. I need to construct the
MailTo: using Javascript so I can customise the outgoing mail message.

--
Terry Burns
http://TrainingOn.net
"news.btinternnet.com" <he**@now.com> wrote in message
news:d8**********@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
Thanks for your help, unfortunately, this was not quite what I was looking
for, perhaps I should have been more specific. I am trying to invoke the
mail helper for the MailTo link. Using the link's click event does this
for IE and NN, but I can invoke the event on NN. I need to construct the
MailTo: using Javascript so I can customise the outgoing mail message.

I know there are other ways of doing this using a form and a bit of CGI
script or whatever, but prefer this method. I know you may say reach is
an issue because not everyon has helpers on their browser, in any case
this is what I am trying to acheive.

Do you know how to invoke the click event programatically in Javascript
( NN ), I would dearly like to know the answer to that ?

Best Regards

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:Ft*****************@news.optus.net.au...
RobG wrote:
news.btinternnet.com wrote:

I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on
the link themselves.
if ( myLink.href ) document.location.href = myLink.href;
I need to be able to do the same in Netscape Navigator,
My install of Navigator is broken, I'm about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)


Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can't follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS 'enhanced' version.
--
Rob


Jul 23 '05 #5
VK
<html>
<head>
<title>Events</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function autoexec() {
var mailLink = document.links[0];
// *********************************
// FF/NN accept programmed events,
// but default action will be taken only
// from hardvare device input:
if (document.createEvent) { // FF model
var customClick = document.createEvent('MouseEvents');
customClick.initEvent('click',0,0);
mailLink.dispatchEvent(customClick);
// The old good click() is removed from link methods:
try {mailLink.click();} catch(e){alert(e.toString());}
}
// *********************************
// IE accepts programmed events,
// but default action will be taken only
// from hardvare device input (like FF/NN):
else if (document.createEventObject) { // IE model
var customClick = document.createEventObject();
mailLink.fireEvent('onclick', customClick);
// The old good click() was simply forgotten
// by the brave IE team and allows to bypass security:
mailLink.click(); // equals to a hardware click
}
else {
/* NOP */
}
// In your case you can use a unofficial sidewalk:
document.location.href = document.links[1].href;
// If W3 comes to kill you, don't blame on me though :-)
// Also over the last 12 years people tried to put all
// kind of nasty crap via mailto, so it's very secured.
// In a *secure browser* you can add nothing but a
// subject line and *one* line of plain text into body.
}
</script>
</head>

<body bgcolor="#FFFFFF" onload="autoexec()">
<p><a href="mailto:sc**********@yahoo.com" onclick="alert('Click
received')">Mail link 1</a></p>
<p><a href="mailto:sc**********@yahoo.com">Mail link 2</a></p>
</body>
</html>

Jul 23 '05 #6
I tried this on NN 7.2 which is what I am testing with ant the assignment
document.location.href = myLink.href; did not work. However, it did work for
IE.

Any ideas ?

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:Ft*****************@news.optus.net.au...
RobG wrote:
news.btinternnet.com wrote:
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on the
link themselves.

if ( myLink.href ) document.location.href = myLink.href;

I need to be able to do the same in Netscape Navigator,

My install of Navigator is broken, I'm about to fix it but I suspect
the above will work fine (it does in IE and Firefox...)


Fixed my NN install, the above fix seems to work fine. If you are
concerned that the link may have an onclick event that may not be
executed if you scrape the href, then try:

if ( myLink.href ) {
if ( ! myLink.onclick ) {
document.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
document.location.href = myLink.href;
}
}
}

This provides a reasonable simulation of a click on an A element
(unless there are some other events - e.g. keyup, keydown, etc. - that
you want to support).

The above looks to see if myLink has an href attribute. If so, it sees
if the onclick intrinsic event is supported, if not, the link is
followed.

If onclick is supported, it attempts to run the onclick() script. If
it returns anything other than - false - the link is followed. If
- false - is returned, then the link is not followed (nothing happens).

However, there is a serious accessibility issue here: users without
JavaScript can't follow the link at all. You must provide an
alternative so that these users can follow links. The usual fix is to
provide normal A elements, then use a script when the page loads to
replace the normal navigation with your JS 'enhanced' version.
--
Rob

Jul 23 '05 #7

I tried this on NN 7.2 which is what I am testing with ant the assignment
document.location.href = myLink.href; did not work. However, it did work for
IE.

Any ideas ?

--
Terry Burns
http://TrainingOn.net
"VK" <sc**********@yahoo.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
<html>
<head>
<title>Events</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<script type="text/javascript">
function autoexec() {
var mailLink = document.links[0];
// *********************************
// FF/NN accept programmed events,
// but default action will be taken only
// from hardvare device input:
if (document.createEvent) { // FF model
var customClick = document.createEvent('MouseEvents');
customClick.initEvent('click',0,0);
mailLink.dispatchEvent(customClick);
// The old good click() is removed from link methods:
try {mailLink.click();} catch(e){alert(e.toString());}
}
// *********************************
// IE accepts programmed events,
// but default action will be taken only
// from hardvare device input (like FF/NN):
else if (document.createEventObject) { // IE model
var customClick = document.createEventObject();
mailLink.fireEvent('onclick', customClick);
// The old good click() was simply forgotten
// by the brave IE team and allows to bypass security:
mailLink.click(); // equals to a hardware click
}
else {
/* NOP */
}
// In your case you can use a unofficial sidewalk:
document.location.href = document.links[1].href;
// If W3 comes to kill you, don't blame on me though :-)
// Also over the last 12 years people tried to put all
// kind of nasty crap via mailto, so it's very secured.
// In a *secure browser* you can add nothing but a
// subject line and *one* line of plain text into body.
}
</script>
</head>

<body bgcolor="#FFFFFF" onload="autoexec()">
<p><a href="mailto:sc**********@yahoo.com" onclick="alert('Click
received')">Mail link 1</a></p>
<p><a href="mailto:sc**********@yahoo.com">Mail link 2</a></p>
</body>
</html>

Jul 23 '05 #8
VK
> I tried this on NN 7.2 ... did not work.

So bravo NN, I guess in the relation of mailto they are even more
secure than FF.

Use forms or leave NN users unattended.

Jul 23 '05 #9
Thanks, I guess , will just have to use forms for NN and leave IE to work as
is.

I just wish NN would die.

:(-

--
Terry Burns
http://TrainingOn.net
"VK" <sc**********@yahoo.com> wrote in message
news:11*********************@z14g2000cwz.googlegro ups.com...
I tried this on NN 7.2 ... did not work.


So bravo NN, I guess in the relation of mailto they are even more
secure than FF.

Use forms or leave NN users unattended.

Jul 23 '05 #10
VK
There were so many years since anyone tried to submit forms to e-mail.
And it was one of NN inventions, so maybe the relevant code is still
sitting in the kernel being lost and forgotten. You may try (I don't
have NN here):

<form name="ghost" action="mailto:sc**********@yahoo.com" method="get">
<a href="foo.html" onclick="
(event.preventDefault)? event.preventDefault() :
event.returnValue=false;
document.forms['ghost'].submit()">Mail link</a>
<input type="hidden" name="subject" value="Ghosts%20of%20the%20past">
<input type="hidden" name="body"
value="Ghosts%20of%20the%20past%0D%0Aare%20still%2 0here">
</form>

IE still remembers it, but it doesn't parse escape sequences this way
(must be a security lock).

Jul 23 '05 #11
VK wrote:
[...]
try {mailLink.click();} catch(e){alert(e.toString());}


I may be wrong, but try..catch here is completely unnecessary.

JavaScript supports object/method/property detection, all that is
required is:

if ( mailLink.click ) mailLink.click();

provided you are confident that 'mailLink' has been properly declared
in the first place. If the click method is not supported, then the
test will return false and it will not be attempted. A belt and braces
approach would be:

if ( mailLink && mailLink.click ) mailLink.click();

There is simply no need for a custom object, try..catch or almost the
entire rest of the script.
As far as I can tell, the click() method for A elements is a Microsoft
invention. The W3C DOM Level 1 and 2 have a click method for input
elements only:

click
Simulate a mouse-click. For INPUT elements whose type attribute has
one of the following values: "Button", "Checkbox", "Radio", "Reset",
or "Submit".
No parameters.
No return value.
No exceptions.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-2651361>

DOM 1 says almost exactly the same thing.

I can't find it in DOM 3 (but that is likely my poor search skills),
nor where it was removed (if it has been). But in any case, try..catch
is not required and feature detection should suffice.

I found and ancient (2000) reference to simulating MS's click event for
A elements in Netscape that was pretty much what I'd proposed.

<URL:http://www.faqts.com/knowledge_base/view.phtml/aid/1122>

That ought to flush out one of the lurking gurus...

[...]
--
Rob
Jul 23 '05 #12
Thanks, but this is beginning to get too messy and unpredictable. I think I
will create a CGI form and only run it if NN ir FF is present, at least
that's going to be more robust. I could not make you're other example work
properly on IE as the default actions didnt seem to want to be averted in my
scenario ?!? .

I hate cross browser problems. 8-|

Thanks for all your help.
"VK" <sc**********@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
There were so many years since anyone tried to submit forms to e-mail.
And it was one of NN inventions, so maybe the relevant code is still
sitting in the kernel being lost and forgotten. You may try (I don't
have NN here):

<form name="ghost" action="mailto:sc**********@yahoo.com" method="get">
<a href="foo.html" onclick="
(event.preventDefault)? event.preventDefault() :
event.returnValue=false;
document.forms['ghost'].submit()">Mail link</a>
<input type="hidden" name="subject" value="Ghosts%20of%20the%20past">
<input type="hidden" name="body"
value="Ghosts%20of%20the%20past%0D%0Aare%20still%2 0here">
</form>

IE still remembers it, but it doesn't parse escape sequences this way
(must be a security lock).

Jul 23 '05 #13
RobG wrote:
[...]

I can't find it in DOM 3 (but that is likely my poor search skills),


Hmm, got that right. Seems that with DOM 3 and XHTML 1.0 any element
can accept a click except for a list of those that obviously shouldn't
(applet, base, basefont, bdo, br, font, frame, frameset, head, html,
iframe, isindex, meta, param, script, style and title).

<URL:http://www.w3.org/TR/2003/NOTE-DOM-Level-3-Events-20031107/events.html#Events-EventTypes-complete>


--
Rob
Jul 23 '05 #14
Doesent work in NN 7.2 unfortunately.

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:42***********************@per-qv1-newsreader-01.iinet.net.au...
VK wrote:
[...]
try {mailLink.click();} catch(e){alert(e.toString());}


I may be wrong, but try..catch here is completely unnecessary.

JavaScript supports object/method/property detection, all that is
required is:

if ( mailLink.click ) mailLink.click();

provided you are confident that 'mailLink' has been properly declared
in the first place. If the click method is not supported, then the
test will return false and it will not be attempted. A belt and braces
approach would be:

if ( mailLink && mailLink.click ) mailLink.click();

There is simply no need for a custom object, try..catch or almost the
entire rest of the script.
As far as I can tell, the click() method for A elements is a Microsoft
invention. The W3C DOM Level 1 and 2 have a click method for input
elements only:

click
Simulate a mouse-click. For INPUT elements whose type attribute has
one of the following values: "Button", "Checkbox", "Radio", "Reset",
or "Submit".
No parameters.
No return value.
No exceptions.

<URL:http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-2651361>

DOM 1 says almost exactly the same thing.

I can't find it in DOM 3 (but that is likely my poor search skills),
nor where it was removed (if it has been). But in any case, try..catch
is not required and feature detection should suffice.

I found and ancient (2000) reference to simulating MS's click event for
A elements in Netscape that was pretty much what I'd proposed.

<URL:http://www.faqts.com/knowledge_base/view.phtml/aid/1122>

That ought to flush out one of the lurking gurus...

[...]
--
Rob

Jul 23 '05 #15
news.btinternnet.com wrote:
Doesent work in NN 7.2 unfortunately.


What?

--
Rob
Jul 23 '05 #16
VK
>> try {mailLink.click();} catch(e){alert(e.toString());}
I may be wrong, but try..catch here is completely unnecessary.
My code is a so called "test case", so the task was not to check the
presence of click() (I already knew it was not there) but to
demonstrate it to OP. And what can be better than the error text in
this case?
<URL:http://www.faqts.com/knowledge*_base/view.phtml/aid/1122>


This effectively equals to document.location.href = linkObject.href,
just a bit complicated by prototyping stuff.

As we know by now, FF/NN lock this trick for mailto: pseudo-protocol
(and God thanks).

The root of the problem is that system finally thought to distinguish
between hardware device input events and programmed pseudo-events. And
programmed pseudo-events have all kind of security limitations
preventing them from "stealing" user interface.

Jul 23 '05 #17
The ancient link you sent me, it does not work in NN 7.2

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:Hg*****************@news.optus.net.au...
news.btinternnet.com wrote:
Doesent work in NN 7.2 unfortunately.


What?

--
Rob

Jul 23 '05 #18
VK
> As we know by now, FF/NN lock this trick for mailto: pseudo-protocol

Error: NN does lock, FF *doesn't* (should be reported?)

Jul 23 '05 #19
DU
RobG wrote:
news.btinternnet.com wrote:
I can do this in IE

myLink.click(); //Invoking the handler as if the user had clicked on
the link themselves.

if ( myLink.href ) document.location.href = myLink.href;


location is an object property of the window object, not of the document
object.

DU
--
The site said to use Internet Explorer 5 or better... so I switched to
Firefox 1.0.4 :)
Jul 23 '05 #20
news.btinternnet.com wrote:

News group etiquette is to write your reply directly beneath a quote of
what you are replying to - that way readers are likely to know what you
are replying to. It also helps to explain why top posting is abhorred.

You appear to be using Outlook Express, which by default puts the
cursor above the quoted text. This is likely intended to allow you to
read from the top and scroll down through the text, you should not just
start typing your reply without regard for others trying to understand
your response.

Some readers of this forum receive the messages as an email. They do
not necessarily see a nice, threaded set of messages. The message
that you are responding to may be in some other e-mail, making it
difficult for e-mail based subscribers to follow the thread. Some of
these users are able to contribute significant knowledge to the group -
annoying them by making your posts hard to follow just means they won't
bother to help you out, they will spend their time helping those that
show consideration for others.

Users who just look at the most recent posts (a very efficient way to
scan posts) are also discouraged from replying. If they see a single
comment out of context they will likely just ignore it. To attempt to
understand your post they must to change to a threaded view, search
through a number of posts in an attempt get the context, then decide
whether to reply or not.

The best practice is to delete anything that you are not replying to
and write your response immediately below the bits that are relevant.
That way anyone reading the post has some idea of the context of your
reply without further effort.
The ancient link you sent me, it does not work in NN 7.2


The link definitely does 'work' in Netscape 7.2 (at least on the one
installed on my PC). But there is no point in pursuing it as the code
was old, it was only really relevant to Netscape Navigator up to
version 4 and did not help your cause of trying to soft-click a mailto:
link.

The bottom line is that the A element does not have a click method
defined in the W3C HTML 4 specification and neither Netscape or Firefox
provide one.

Replacing window.location.href with the href of the A element works as
well as can be expected. If the user has a mail client configured and
JavaScript enabled, then something happens. For me, Netscape kept
opening its own mail client, not my preferred mail client (but I
suspect that is an install problem and not a 'bug' in Netscape). IE
and Firefox opened the correct mail client.

Here is some code with the correction suggested by DU. It's been
tested in IE, Firefox and Netscape 7.2:
<a id="mto" href="mailto:ro**@rob.com">mailto</a><br>
<input type="button" value="Click the mailto..."
onclick="clickIt('mto');">

<script type="text/javascript">
function clickIt(x){
var myLink = ( document.getElementById )?
document.getElementById(x) : document.all[x];
if ( myLink.click ) {
myLink.click();
} else if ( myLink.href ) {
if ( ! myLink.onclick ) {
window.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
window.location.href = myLink.href;
}
}
}
}
</script>
But all that seems way over the top. Why not just replace the href
from the button's onclick event:

<input type="button" value="e-mail me..." onclick="
window.location.href = 'mailto:ro**@rob.com';
">

--
Rob
Jul 23 '05 #21
Thanks, but I really do not need an lesson in etiquette from you. Normally I
follow the prescribed format, however there are times when bevity is forced
by circumstance and that was one of those times. The 'Ancient Link' you
provided definately did not work on my machine.

I will test the code you provided in your last post and let you know how it
works for me.

Thank you for your time in any case.

--
Terry Burns
http://TrainingOn.net
"RobG" <rg***@iinet.net.auau> wrote in message
news:2w*****************@news.optus.net.au...
news.btinternnet.com wrote:

News group etiquette is to write your reply directly beneath a quote of
what you are replying to - that way readers are likely to know what you
are replying to. It also helps to explain why top posting is abhorred.

You appear to be using Outlook Express, which by default puts the
cursor above the quoted text. This is likely intended to allow you to
read from the top and scroll down through the text, you should not just
start typing your reply without regard for others trying to understand
your response.

Some readers of this forum receive the messages as an email. They do
not necessarily see a nice, threaded set of messages. The message
that you are responding to may be in some other e-mail, making it
difficult for e-mail based subscribers to follow the thread. Some of
these users are able to contribute significant knowledge to the group -
annoying them by making your posts hard to follow just means they won't
bother to help you out, they will spend their time helping those that
show consideration for others.

Users who just look at the most recent posts (a very efficient way to
scan posts) are also discouraged from replying. If they see a single
comment out of context they will likely just ignore it. To attempt to
understand your post they must to change to a threaded view, search
through a number of posts in an attempt get the context, then decide
whether to reply or not.

The best practice is to delete anything that you are not replying to
and write your response immediately below the bits that are relevant.
That way anyone reading the post has some idea of the context of your
reply without further effort.
The ancient link you sent me, it does not work in NN 7.2


The link definitely does 'work' in Netscape 7.2 (at least on the one
installed on my PC). But there is no point in pursuing it as the code
was old, it was only really relevant to Netscape Navigator up to
version 4 and did not help your cause of trying to soft-click a mailto:
link.

The bottom line is that the A element does not have a click method
defined in the W3C HTML 4 specification and neither Netscape or Firefox
provide one.

Replacing window.location.href with the href of the A element works as
well as can be expected. If the user has a mail client configured and
JavaScript enabled, then something happens. For me, Netscape kept
opening its own mail client, not my preferred mail client (but I
suspect that is an install problem and not a 'bug' in Netscape). IE
and Firefox opened the correct mail client.

Here is some code with the correction suggested by DU. It's been
tested in IE, Firefox and Netscape 7.2:
<a id="mto" href="mailto:ro**@rob.com">mailto</a><br>
<input type="button" value="Click the mailto..."
onclick="clickIt('mto');">

<script type="text/javascript">
function clickIt(x){
var myLink = ( document.getElementById )?
document.getElementById(x) : document.all[x];
if ( myLink.click ) {
myLink.click();
} else if ( myLink.href ) {
if ( ! myLink.onclick ) {
window.location.href = myLink.href;
} else {
if ( false != myLink.onclick() ) {
window.location.href = myLink.href;
}
}
}
}
</script>
But all that seems way over the top. Why not just replace the href
from the button's onclick event:

<input type="button" value="e-mail me..." onclick="
window.location.href = 'mailto:ro**@rob.com';
">

--
Rob

Jul 23 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: rachel | last post by:
Hi all, I am new in ASP.Net. I have a question on link multiple web forms together. Here is the scenario: I create an Index.aspx WebForm which consists of a banner and three navigator...
7
by: Paul Cooper | last post by:
Dear All, I am working on a piece of Javascript code that needs to detect a mouse-click, shift-click and control-click. The code is not my own - it is a part of a much larger suite of routines....
1
by: Olav Tollefsen | last post by:
I have created a client side script that is supposed to invoke the Click event handler on a button. The problem is that it doesn't work. Instead the page is refreshed an Page_Load is invoked, but...
4
by: Miguel Dias Moura | last post by:
Hello, I created a datalist in an ASP.Net / VB page. I display the image and price of a few products. When a user clicks an image I want to load the page "detail.aspx?number=id" and send the...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
15
by: Oleg Subachev | last post by:
I need to programmatically invoke from other class Click event of the Button on my Form. Button.OnClick method is protected, not public. How to perform this ? Oleg Subachev
11
by: cindy | last post by:
I have a form, has javascript registered so a modal pops up. Button click will close form. Now I need to do an update with modal form data before it closes. I can put a second button and register...
7
by: the_grove_man | last post by:
How do I invoke a "Right-Click" Programmtically? John
8
by: squash+go | last post by:
For an abstract algebra class that I will be teaching, I'm trying to convert a text-based game that I wrote in Common Lisp to a graphical game in javascript. (I know nothing of javascript, but I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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,...

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.