473,406 Members | 2,217 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,406 software developers and data experts.

greasemonkey specific javascript irregularities

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 not triggered .
no error shown in javascript console as well . any idea ?

// JavaScript Document
window.addEventListener("load", function() {
var i=0;
draw();

function draw(){
var t = document.createElement("div");
t.innerHTML = "<div id=\"div1\" style=\"margin: 0 auto 0
auto;\"><input name=\"submit\" type=\"submit\" id='btnStart'
value=\"Start\"></div>";
document.body.insertBefore(t, document.body.firstChild);
document.getElementById('btnStart').setAttribute(" click",
function()
{start()},false);
}

function start(){
alert('started');
}

},false);

the div1 is shown, but events are not triggered . sometimes i get a
funciton not defined as well.

Keep Clicking,
Bosky

Jun 4 '06 #1
4 2186


bo******@gmail.com wrote:

document.getElementById('btnStart').setAttribute(" click",
function()
{start()},false);

I think you want
document.getElementById('btnStart').addEventListen er("click",
function()
{start()},false);

Using setAttribute with a function argument and a third argument does
not make sense with Mozilla/Firefox and Greasemonkey scripts.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 4 '06 #2
wrote in news:11**********************@g10g2000cwb.googlegr oups.com in
comp.lang.javascript:
alright ive heard a lot about the onclick being needing to be replaced
with click
[snip]
document.getElementById('btnStart').setAttribute(" click",
function()
{start()},false);

document.getElementById('btnStart').addEventListen er(
"click",
function() {start()},
false
);

The event is called "click" the attribute is called "onclick".

Either of:

document.getElementById('btnStart').onclick = function() {start()};
document.getElementById('btnStart').setAttribute(
"onclick",
"alert('started');"
);

Will also work.
}

function start(){
alert('started');
}

},false);


Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jun 4 '06 #3
thanks guys ...


now ive come across one more problem .the dreaded 'permissions' denial
..

i have the folowing two lines appended in prefs.js:
user_pref("capability.principal.codebase.p0.grante d",
"UniversalBrowserRead");
user_pref("signed.applets.codebase_principal_suppo rt", true);

the ajax calls in my greasemonkey code goes as follows :

if (window.XMLHttpRequest)
{ //FF
setSecurity();
req = new XMLHttpRequest();
[snip]
..
..
..

[/snip]
setSecurity();
req.open("GET", dest, true);
[snip/]

function setSecurity(){
try {
netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserRead");
netscape.security.PrivilegeManager.enablePrivilege ("UniversalBrowserWrite");
}
catch (e) {
alert('Permission UniversalBrowserRead denied.');
}
}

now when i embed this code in html it works well. i still get the
Permission UniversalBrowserRead denied. message (exception caught) .
where am i going wrong ?

Thanks again ...
- Bhasker

Jun 4 '06 #4
1) actaully i seem to be getting a 'netscape is not defined' message in
my exception. bugzilla.mozilla.org/show_bug.cgi?id=35116 says that
changing prefs.js ,and then restarting firefox will give the 'netscape
is not defined' message. but i kept restarting FF . still no luck.

2)searching on the 'right' methods to apply privileges in firefox (
without signing ),i came across
http://almaer.com/blog/archives/cat_tech.html that says that :

function securePrivilege(priv) {
// insert the try/catch code from above, plus anything for the
other browsers
}

and then calling securePrivilege('UniversalBrowserRead') WILL NOT WORK
at all !... the privilege that you secure, is only applied in that
scope. This means that the priviledge is only even around INSIDE
securePrivilege(priv), and is thus useless " .... IS this true ?

2) does that mean that the FOLLOWING also will not work since its in a
if/else scope?! :

if (typeof netscape != 'undefined' && typeof netscape.security
!='undefined') {
try
{
netscape.security.PrivilegeManager.enablePrivilege ('UniversalBrowserRead');}catch(e){alert(e.message );}
}

else{ alert(e.message);}
req.open("GET", dest, true);
..
..

3) i also tried avoiding the priveleges line ,and simply depending on
appending a user_pref("signed.applets.codebase_principal_suppo rt",
true); in prefs.js . it STILL dint work .

4)most of the tutorials and guides give incomplete implementations and
just say add a line ,and presto! it shud work . does anyone have a
working example including the xmlhttprequest calls ,and WHERE EXACTLY
to call the privilege setting lines ?

Keep Clicking,
bosky

Jun 4 '06 #5

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...
3
by: Matej | last post by:
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...
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...
2
by: 9icj4u613jeqrx8 | last post by:
Hi, I need some help with IE browser programming (in .NET). I'm trying to add a button to the IE toolbar, and on the click of the button open a popup window with a remote URL. Secondly, I'm...
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: nmccart | last post by:
Greetings. I have recently discovered the Grease Monkey add-in for FireFox. It has a lot of potential, and I am really enjoying using it to simplify and automate some repetitive tasks I perform on...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.