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

invoke link click event in Navigator

P: n/a
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
Share this Question
Share on Google+
21 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
news.btinternnet.com wrote:
Doesent work in NN 7.2 unfortunately.


What?

--
Rob
Jul 23 '05 #16

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.