I
ICPooreMan
I've got some code which works in firefox that's giving me fits in
IE7 (maybe other versions too I haven't tested it). What I want to do
is get the oncontextmenu attribute of something, change the value then
put it back as the oncontextmenu attribute.
Here's an example page if you want to try it out...
<html>
<head>
<title> testing </title>
<script><!--
function doSomething(){
var someText =
String(document.getElementById('div1').getAttribute('oncontextmenu'));
someText = someText.replace("Hello","World");
document.getElementById('div1').setAttribute('oncontextmenu',
someText);
}
//-->
</script>
</head>
<body>
<div id="div1" onclick="doSomething();return false;"
oncontextmenu="alert('Hello World');return false;"> Hello </div>
</body>
</html>
The problem is after the onclick event oncontextmenu no longer works.
I've figured out that the reason is that I cast the value of
oncontextmenu to a string. Without that cast setAttribute will work
correctly. However without the cast the replace method will not work.
So I either need a way to cast the variable back or do a replace
without the cast.
ps this works fine in firefox
IE7 (maybe other versions too I haven't tested it). What I want to do
is get the oncontextmenu attribute of something, change the value then
put it back as the oncontextmenu attribute.
Here's an example page if you want to try it out...
<html>
<head>
<title> testing </title>
<script><!--
function doSomething(){
var someText =
String(document.getElementById('div1').getAttribute('oncontextmenu'));
someText = someText.replace("Hello","World");
document.getElementById('div1').setAttribute('oncontextmenu',
someText);
}
//-->
</script>
</head>
<body>
<div id="div1" onclick="doSomething();return false;"
oncontextmenu="alert('Hello World');return false;"> Hello </div>
</body>
</html>
The problem is after the onclick event oncontextmenu no longer works.
I've figured out that the reason is that I cast the value of
oncontextmenu to a string. Without that cast setAttribute will work
correctly. However without the cast the replace method will not work.
So I either need a way to cast the variable back or do a replace
without the cast.
ps this works fine in firefox