View Full Version : [ASK]Overlay?? Is that possible?

Jan 6th, 2007, 04:09 PM
Is that possible if we wanna 'destroy' all the current page html content, and then replace it with the new one using javascript?
Please tell me folks?!:thumbsup:

Jan 7th, 2007, 12:17 AM
I think it kind of depends what you mean by "all". All visible info on the page? All info even non-visible? You can try something like this to see what might answer your question.

<button onclick="document.write('hi');">Hi</button>


Jan 7th, 2007, 08:21 AM
I guess you must detail your aim. You may do that using javascript, but why to do to that when you may simply load another page...?

Jan 8th, 2007, 11:28 PM
I mean the visible one to be replaced..
Yeah, that example you given is working like an overlay.
But what about the full HTML page to be replaced??:confused:
I'm looking for these anywhere, but not find it out...

Jan 8th, 2007, 11:43 PM
I'm sure I drive Kor crazy with my non-DOM answers but how about this!

<button onclick="document.getElementsByTagName('body')[0].innerHTML='<div>Click <a href=\'http://www.google.com\'>here</a> to go to Google.</div>';">Make new page</button>

I have to admit I still don't understand what you are trying to achieve.


Jan 10th, 2007, 03:13 PM
okay thanks its working, but only replaced the body tag..
what about all inside the HTML tag to be replaced?
Can this be done?

Jan 10th, 2007, 04:47 PM
Ok I'm done guessing. First I showed one way to overwrite the whole thing and you said you only wanted the visible stuff replaced. Then I showed a way to replace the body and you want to replace more. I'd need solid information on what you do and don't want changed to try and help more.


Jan 11th, 2007, 09:28 AM
Okay, sorry for the less info i've given...
The detail is:
I want to replace all the tag inside the HTML tag..
including head and body tag...

So that's it..
I wanted to make a site that when some1 click the link the page are all updated with the new one..

Jan 11th, 2007, 05:07 PM
Well I don't have any idea how to set everything between the <html> tags. From my limited tests the

document.getElementsByTagName('html')[o].innerHTML =

assignment didn't work.

But it seemed to work to overwrite the whole page using document.write() as shown in this test.

<title>Old Page</title>
<script type="text/javascript">
var htmlHead =
"<title>New Page</title><script>function set(){document.getElementById('adiv').innerHTML='adiv';}<\/script>";
var htmlBody =
"<div>Click <a href='http://www.google.com'>here</a> to go to Google.</div><button onclick='set();'>Test DOM</button><div id='adiv' />";
var htmlPage =
"<html><head>" + htmlHead + "</head><body>" + htmlBody + "</body></html>";
<button onclick="document.write(htmlPage); document.close();">Replace with document.write</button>

Of course, I have no idea what the ramifications are across browsers or anything else. But it was interesting that it did seem to parse it in to the DOM (as shown by the button).