PDA

View Full Version : Call XMLHttpRequest



odelyag
07-03-2008, 07:57 AM
Hi,

I have a problem.
I need to call a javascript function that the code is uses document.write.

For example:

function hello{
document.write('hello')
}

(it's a build-in functino from a third party component that we bought).
I would like to print the 'hello' into a specific div.
if i call the method, it writes it the page as it is.
Is there a way to get it to string without changing the function?

codeexploiter
07-03-2008, 08:34 AM
If you try to use document.write from a window which has loaded completely it the page will be completely repainted with the new content. So it is better if you avoid the usage of document.write in your case.

Have a look at the below source code and see if this is what you are trying to achive.



<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Untitled Document</title>
<style type="text/css">
#content{
width:900px;
height: 100px;
border:1px solid red;
background-color: #E1E1E2;
font-size:small;
font-family:Arial, Helvetica, sans-serif;
color:#77AFFC;
}
</style>
<script type="text/javascript">
function insertContent(str){
document.getElementById('content').innerHTML = str;
}
</script>
</head>
<body>
<div id="content"></div>
<form name="f">
<input type="button" value="Insert Content" onclick="insertContent('This is a test content');" name="insert" />
</form>
</body>
</html>


There is no point in using a subject not related to your acutal problem.

Hope this help.

odelyag
07-03-2008, 09:15 AM
it doesn't help me..
since the function is from a third party.
So i can't change the document.write option that it offers...
what will be another solution to use their script without changing it?

codeexploiter
07-03-2008, 09:24 AM
Executing their function before the window loading completes. Using an iframe might help but it is better if you can avoid them.

odelyag
07-03-2008, 09:25 AM
what do you mean? if i have a timer to do it every 2 minutes, it will be after the page load!

odelyag
07-03-2008, 09:31 AM
what do you mean? if i have a timer to do it every 2 minutes, it will be after the page load!