473,385 Members | 1,359 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,385 software developers and data experts.

greasemonkey and onclick

Hi,

I try to assign my function to one <A> element in this GM script, but
it doesn't work as hoped for (after pressing Alt+L in Firefox 1.5
nothing happens). Does anybody see what I am doing wrong here?

window.openNewLocation = function() {
alert("OK");
}

var ATags = document.getElementsByTagName("a");
var hrefArray = window.location.href.split("/");
hrefArray[hrefArray.length-1] = "gallery";
var imageHREF = hrefArray.join("/");

// window.open(this.href,'extern').focus();return false"
// http://cingular.rbmfrontline.com/locations

for (var i = 0; i < ATags.length; i++)
{
tempElem = ATags[i];
if (tempElem.getAttribute("href") ==
"http://cingular.rbmfrontline.com/locations") {
tempElem.accesskey = "L";
tempElem.onClick = "function() {openNewLocation();return false}";
GM_log('attributes = ' + String(tempElem.onClick));
}
};

Thanks a lot,

Matej

Mar 2 '06 #1
3 6013


Matej wrote:

var ATags = document.getElementsByTagName("a"); for (var i = 0; i < ATags.length; i++)
{
tempElem = ATags[i];
if (tempElem.getAttribute("href") ==
"http://cingular.rbmfrontline.com/locations") {
tempElem.accesskey = "L";
The DOM property is named accessKey, see
<http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-89647724>
so as always with JavaScript the case matters.
tempElem.onClick = "function() {openNewLocation();return false}";


Case matters again, the event handlers in DOM are all lower case so
tempElem.onclick
is needed. Then you would need to assign a function object and not a
string e.g.
tempElem.onclick = function (evt) {
openNewLoation();
if (typeof evt != 'undefined' && typeof evt.preventDefault) {
evt.preventDefault();
}
return false;
};

However as you say you are writing a GreaseMonkey script then scripting
onclick is not going to work, see
<http://diveintogreasemonkey.org/patterns/intercept-clicks.html>
but you should simple do
tempElem.addEventListener(
'click',
function (evt) {
openNewLoation();
evt.preventDefault();
return false;
},
false
);
--

Martin Honnen
http://JavaScript.FAQTs.com/
Mar 2 '06 #2
You are partially right -- I have to use addEventListener, but my
script doesn't work. I will ask for more info on GM list.

Thanks,

Matej

Mar 2 '06 #3
And yes, it was my wrong capitalization of accessKey property.

Thanks,

Matej

Mar 2 '06 #4

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

Similar topics

2
by: Newton | last post by:
I'm having some issues with a greasemonkey script i've made (nothing serious, and you'll notice that by the mess). I made it to learn javascript properly at first but it ended handy and now i'm...
4
by: bosky101 | last post by:
alright ive heard a lot about the onclick being needing to be replaced with click ,and some other healthy practices like that . but im still not able to figure out the problem . my click event is...
3
by: Alex | last post by:
Sorry if this is not a correct forum to post to. I have a page from my service provider that loads 1000's of table cells. These cells load for 3-4 mins and links on that page usually not...
2
by: Alexander Paul | last post by:
Hi! I'm a newbie to JavaScript and Greasemonkey and just started learning with 'Dive Into Greasemonkey'. I looked for an example on the web, but unfortunately I'm still missing something... I...
3
XtinaS
by: XtinaS | last post by:
I'm trying to write a script for Greasemonkey that will, in LiveJournal, replace a placeholdered embedded YouTube thing with a link to the video. In LiveJournal, you can set an option to have a...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.