/    Sign up×
Community /Pin to ProfileBookmark

Help me… i’m feeling down!

obj_Font = window.opener.document.createElement(“FONT”);
obj_Font.style.cursor = ‘hand’;
[COLOR=red]obj_Font.onclick = new Function(“alert(‘YO’)”);[/COLOR]
obj_Text = window.opener.document.createTextNode(‘eliminar’);
obj_Font.appendChild(obj_Text);

Anyone knows how can i make the red colored code work?!?

to post a comment
JavaScript

11 Comments(s)

Copy linkTweet thisAlerts:
@pyroDec 12.2003 — Try it like this:

obj_Font.onclick = new function() { alert('YO'); }
Copy linkTweet thisAlerts:
@fredmvDec 12.2003 — obj_Font.setAttribute('onclick', 'alert("foo");');
Copy linkTweet thisAlerts:
@xondokanauthorDec 12.2003 — No, and No!

None of those solutions seems to work!

thanks anyway!

?
Copy linkTweet thisAlerts:
@fredmvDec 12.2003 — You must be doing something wrong then. This works fine for me:<script type="text/javascript">
//<![CDATA[
onload = function()
{
var d = document.createElement('div');
d.setAttribute('onclick', 'alert("foo");');
d.appendChild(document.createTextNode('bar'));
document.body.appendChild(d);
}
//]]>
</script>
Copy linkTweet thisAlerts:
@xondokanauthorDec 12.2003 — yes... that would work for me as well... but the problem here, is that i'm creating the object in the "opener" window, and the code you wrote is creating it in the "self" window.
Copy linkTweet thisAlerts:
@fredmvDec 12.2003 — Then you need to find out what you're doing wrong and correct it. The code you need is above and all you have to do is slightly modify it.
Copy linkTweet thisAlerts:
@AdamBrillDec 12.2003 — I don't think you can add event handlers onto the parent window, but I'm not sure. If you post a link to where you have your page, it would be easier to be sure of the problem. ?
Copy linkTweet thisAlerts:
@fredmvDec 12.2003 — See attachment.

[upl-file uuid=3a6be2a0-a0e3-4da0-b04d-6b1a2cb17c5f size=1kB]event.zip[/upl-file]
Copy linkTweet thisAlerts:
@AdamBrillDec 12.2003 — fredmv, that didn't work for me. I don't know if it worked for anyone else, but I got an access denied error when trying to append the child... Did that code work for you??
Copy linkTweet thisAlerts:
@fredmvDec 12.2003 — Interesting. I should've tested it under more browsers, I only tested it under Mozilla 1.6a and it worked perfectly. I'll have to look over the code. Thanks for catching that error Adam.
Copy linkTweet thisAlerts:
@fredmvDec 13.2003 — Alright, I just created an alternative method in which is used if the browser encounters errors while executing the original code. Opera 7.23 and IE6 both had troubles with the original code where Mozilla 1.6a executed it flawlessly. What I did was, basically, is use non-DOM methods to create the element and attach event handlers, and a [font=courier]try/catch[/font] block to first test the original code, and then use the non-DOM code if errors are encountered. See attachment for the revised version.

[upl-file uuid=b5647319-82c6-4c74-beca-195946cd8f6c size=1kB]event.zip[/upl-file]
×

Success!

Help @xondokan spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...