Solved

Dynamically Editting <BODY> Tag

Posted on 2001-06-25
4
255 Views
Last Modified: 2008-03-04
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'].document.body.outerHTML;
var BodyPos = (RightOuterHTML.indexOf('<BODY'))+6;
var beginstring = RightOuterHTML.substring(0,BodyPos);
var endstring     = RightOuterHTML.substring(BodyPos);
var code = "onscroll=\"alert('Scroll');\" ";
var totalstring = beginstring + code + endstring;
parent.frames['Right'].document.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...
0
Comment
Question by:rose337
  • 2
  • 2
4 Comments
 
LVL 5

Expert Comment

by:djbusychild
ID: 6225076
why don't you just register an event handler?

<html>
<head>

<script>
function handleScroll() {
     alert("YOU ARE SCROLLING");
}

function activate() {
     document.body.onscroll=handleScroll;
}
</script>

</head>
<body>

<button onclick="activate();">click</button>

<img width="800" height="600" />
</body>

</html>
0
 

Author Comment

by:rose337
ID: 6226388
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?
0
 
LVL 5

Accepted Solution

by:
djbusychild earned 100 total points
ID: 6226402
I don't think that makes any difference.

you can still refer to the document of the frame

parent.frames["right"].document.body.onscroll
0
 

Author Comment

by:rose337
ID: 6226416
Works great! Thanks...
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delay Form Submission without touching existing code? 5 22
Jquery GMAP3 Hierarchy 1 27
CSS: Making Pure CSS read more boxes thinner 5 31
JS does not refresh 6 18
In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question