__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
For some reason my page keeps continuously loading
Code:
<html>
<head>
<script type="text/javascript">
function replacetop() {
var topbefore="before";
var topafter="newfore";
document.write(document.body.innerHTML.replace(topbefore,topafter));
}
function replacebottom() {
var bottombefore="after";
var bottomafter="aftore";
document.write(document.body.innerHTML.replace(bottombefore,bottomafter));
}
</script>
</head>
<body>
<form>
<input type="button" onclick="replacetop()" value="Call function">
<input type="button" onclick="replacebottom()" value="Call function">
</form>
before ME after
</body>
</html>
It's because you are running it as a document.write in the head, doing that will replace the whole document with whatever you write back.
load the body innerHTML into a string, replace and put the text back in to the body.
eg:
Code:
function before() {
var m_reBefore= /before/g;
var m_sAfter="after";
var m_sStr = document.body.innerHTML.replace(m_reBefore,m_sAfter);
document.body.innerHTML = m_sStr;
}
__________________
Chris. ->> Please login or register to view this content. Registration is FREE <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?