rose337
asked on
Dynamically Editting <BODY> Tag
Good day. I want to dynamically change at run time
from
<BODY>
Blah Blah Blah
</BODY>
to
<BODY onscroll="alert('I am scrolling');">
Blah Blah Blah
</BODY>
Now I have have two frames called Left and Right. I manipulated the outerHTML property of the Right document by doing this
var RightOuterHTML = parent.frames['Right'].doc ument.body .outerHTML ;
var BodyPos = (RightOuterHTML.indexOf('< BODY'))+6;
var beginstring = RightOuterHTML.substring(0 ,BodyPos);
var endstring = RightOuterHTML.substring(B odyPos);
var code = "onscroll=\"alert('Scroll' );\" ";
var totalstring = beginstring + code + endstring;
parent.frames['Right'].doc ument.body .outerHTML = totalstring;
Which, as you can see, finds the <BODY tag and splits the outerHTML string into two pieces, then adds the code, and rejoins all the pieces into the outerHTML string. This is painful but works all the way to the last line and gives a runtime error. It appears not to like replacing the outerHTML string.
Does anyone have a better idea of doing this? Or at least knows what I am doing wrong?
Thanks...
from
<BODY>
Blah Blah Blah
</BODY>
to
<BODY onscroll="alert('I am scrolling');">
Blah Blah Blah
</BODY>
Now I have have two frames called Left and Right. I manipulated the outerHTML property of the Right document by doing this
var RightOuterHTML = parent.frames['Right'].doc
var BodyPos = (RightOuterHTML.indexOf('<
var beginstring = RightOuterHTML.substring(0
var endstring = RightOuterHTML.substring(B
var code = "onscroll=\"alert('Scroll'
var totalstring = beginstring + code + endstring;
parent.frames['Right'].doc
Which, as you can see, finds the <BODY tag and splits the outerHTML string into two pieces, then adds the code, and rejoins all the pieces into the outerHTML string. This is painful but works all the way to the last line and gives a runtime error. It appears not to like replacing the outerHTML string.
Does anyone have a better idea of doing this? Or at least knows what I am doing wrong?
Thanks...
ASKER
I would except that I have 50 pages that I have to do this to. But they all pop up in the right frame by clicking a link from a menu in the left frame. So I am adding javascript to the link, so that when the link is pressed, the page loads in the right frame, and then the scrolling code is added to to page in the right frame. Therefore, I do not have to added 50 pieces of the same code, but rather 1 piece of code to the left frame, and life is easy. Well, that is the theory. So any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Works great! Thanks...
<html>
<head>
<script>
function handleScroll() {
alert("YOU ARE SCROLLING");
}
function activate() {
document.body.onscroll=han
}
</script>
</head>
<body>
<button onclick="activate();">clic
<img width="800" height="600" />
</body>
</html>