PDA

View Full Version : iframe desigmode="On" and catch mouse-clicks


aEr_aEr
10-29-2002, 08:42 AM
I'am working on a wysiwyg editor and i would like to catch the mouse-buttons that are pressed inside the iframe
so i can make my own context menu. All works fine but as soon as i put the designmode on the javascript function
for the clicks doesn't work anymore.

here's the code


<%=nameFrame%>.focus();
<%=nameFrame%>.isHTMLMode = false;

<%=nameFrame%>.document.write('<HTML><HEAD><title>asdfs</title><script language=JavaScript>
var message="Function Disabled!"; function click(){ if (event.button==2){ alert(message); return false; }}
document.onmousedown=click; <'+'/script></HEAD><BODY><link REL="stylesheet" href="'+styleCSS+'" TYPE="text/css"><%=data%></BODY></HTML>');

<%=nameFrame%>.document.designMode="On";
<%=nameFrame%>.focus();



If i leave the designmode="On" away and i press the right mouse button
i get the message, but as soon as i put it back in my code it won't
work anymore.

What am i doing wrong

joh6nn
10-29-2002, 12:53 PM
click is already a function in javascript: naming a function "click", is going to cause problems. i suggest renaming it. if that doesn't help, then i think we'll need to see what the rest of the code is.

aEr_aEr
10-29-2002, 01:01 PM
thnx for the reply

I renamed the function to clicker and cleaned out some things and got the following code

<html>
<head>
<script>
var message='Function Disabled!';
function clicker(){
alert(message);
return false;
}

function init(){
test1.document.designMode="On";
}
</script>
</head>
<body onload="init()">
<iframe id=test1 style="width:100px; height:100px" ></iframe>
</body>
<script>

test1.document.write('<HTML><BODY>test</BODY></HTML>');
test1.document.designMode="On";
test1.document.oncontextMenu = clicker();
</script>
</html>


I also tried the same thing whit onclick.

joh6nn
10-29-2002, 01:05 PM
ok, i see something now that i didn't see before.

you're writing to a new document, but you don't ever close that document. often, if you don't close the document, then the browser never really finishes loading it. try:

test1.document.write('<HTML><BODY>test</BODY></HTML>');
test1.document.close();

aEr_aEr
10-29-2002, 01:09 PM
I've tried that and still the same problem

I get the allert message 1 time, when the page is just loaded.
but when i right-click on the iframe it still gives the normal context menu

aEr_aEr
10-30-2002, 12:59 PM
I've searched for a while now and i think it isn't even posible.
Its only posible if i make it in the "DHTML editing control" from microsoft.

Has anyone experience with this editing control on how to get it implemented in a working wysiwyg editor.

Or is there anyone who thinks its possible to change the context menu in a iframe when the designmode is on.

I don't know what to try after 4 days of puzzling. So if anyone has any sugestions on how to get the context menu in a iframe.

joh6nn
10-30-2002, 05:16 PM
test1.document.oncontextMenu = clicker();

i can't believe i didn't notice that before. when you assign functions to event handlers, you're not supposed to include the parenthesis. this is because, with the parenthesis, you're actually calling the function. without the parenthesis, you're assigning the value of variable clicker ( and that value is a function ) to the document's onContextMenu property.

hopefully, that should solve the problem for you.

aEr_aEr
10-31-2002, 06:46 AM
thnx for you're help again.

Yeah you're right on the (), i noticed that also yesterday.
If i leave the () away i don't get the alert message when the page loads, but i still don't get the message when i right click on the i-frame.
I don't think that it is possible, because this is

<html>
<head>
<script>
var message='Function Disabled!';
function clicker(){
alert(message);
return false;
}

function init(){
test1.document.designMode="On";
}
</script>
</head>
<body onload="init()">
<iframe id=test1 style="width:100px; height:100px" ></iframe>
</body>
<script>

test1.document.write('<HTML><BODY>test</BODY></HTML>');
test1.document.designMode="On";
test1.document.oncontextMenu = clicker;
</script>
</html>

a simple peace of code and it still doesn't work.

btw. : I'am testing with ie6

joh6nn
10-31-2002, 08:27 AM
test1.document.oncontextMenu = clicker;

test1.document.oncontextmenu = clicker;

that's another thing that i should have seen sooner. if you change the M to lowercase, it works fine.

aEr_aEr
10-31-2002, 08:38 AM
Thnx very much,
I almost give it up

It fanily works with you're help.

thnx for your help