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 ?
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
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
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:FtRoe.1918$Zn.9...@news.optus.net.au...
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:d80pkm$5k7$1...@nwrdmz02.dmz.ncs.ea.ibs-infra.bt.com...
<body bgcolor="#FFFFFF" onload="autoexec()">
<p><a href="mailto:school...@yahoo.com" onclick="alert('Click
received')">Mail link 1</a></p>
<p><a href="mailto:school...@yahoo.com">Mail link 2</a></p>
</body>
</html>
Any ideas ?
--
Terry Burns
http://TrainingOn.net
"RobG" <rg...@iinet.net.auau> wrote in message
news:FtRoe.1918$Zn.9...@news.optus.net.au...
Any ideas ?
--
Terry Burns
http://TrainingOn.net
"VK" <school...@yahoo.com> wrote in message
news:1118046433.6...@o13g2000cwo.googlegroups.com...
So bravo NN, I guess in the relation of mailto they are even more
secure than FF.
Use forms or leave NN users unattended.
I just wish NN would die.
:(-
--
Terry Burns
http://TrainingOn.net
"VK" <school...@yahoo.com> wrote in message
news:1118054519....@z14g2000cwz.googlegroups.com...
<form name="ghost" action="mailto:school...@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%20here">
</form>
IE still remembers it, but it doesn't parse escape sequences this way
(must be a security lock).
> 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
I hate cross browser problems. 8-|
Thanks for all your help.
"VK" <school...@yahoo.com> wrote in message
news:1118057584....@o13g2000cwo.googlegroups.com...
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
--
Terry Burns
http://TrainingOn.net
"RobG" <rg...@iinet.net.auau> wrote in message
news:42a463f1$0$10171$5a62...@per-qv1-newsreader-01.iinet.net.au...
> 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.
--
Terry Burns
http://TrainingOn.net
"RobG" <rg...@iinet.net.auau> wrote in message
news:Hg4pe.1931$Zn.9...@news.optus.net.au...
Error: NN does lock, FF *doesn't* (should be reported?)
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 :)
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
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:2wrpe.1975$Zn.9...@news.optus.net.au...