Page 1 of 1

Source code...

Posted: Sun Sep 24, 2006 1:04 am
by JellyFish
In Javascript, what property controls the window/frame's source code?

Posted: Sun Sep 24, 2006 3:33 am
by aaronhall
What part of it? What are you trying to control?

Posted: Sun Sep 24, 2006 2:11 pm
by JellyFish
The source code. Example, window.sourceCode = "Anyhtml I want";

Posted: Sun Sep 24, 2006 2:30 pm
by Chris Corbyn
JellyFish wrote:The source code. Example, window.sourceCode = "Anyhtml I want";
document.body.innerHTML ?

Posted: Sun Sep 24, 2006 2:36 pm
by JellyFish
Yeah maybe. I'm not sure.

Posted: Sun Sep 24, 2006 2:46 pm
by Luke
hmm... try it maybe? :roll: :lol:

Posted: Sun Sep 24, 2006 2:51 pm
by JellyFish
I wanna be able to change the complete source code of the window or frame. I want to be able to change the body tags and what's inside the head tags and even DTD tags.

Posted: Sun Sep 24, 2006 3:52 pm
by Chris Corbyn
JellyFish wrote:I wanna be able to change the complete source code of the window or frame. I want to be able to change the body tags and what's inside the head tags and even DTD tags.
Seriously, read up on DOM it's marvelous!

Some wacky and wonderful things you can do with DOM...

Incuding a JavaScript document dynamically (like include() in PHP)

Code: Select all

function include(path)
{
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = path;
    document.getElementsByTagName('head').item(0).appendChild(newScript);
}

include('myscript.js');
Changing a web page via AJAX:

Code: Select all

function onAjaxResponse()
{
    if (ajaxObj.readyState == 4)
    {
        document.body.innerHTML = ajaxObj.responseText;
    }
}

Posted: Sun Sep 24, 2006 3:58 pm
by alex.barylski
d11wtq wrote:
JellyFish wrote:I wanna be able to change the complete source code of the window or frame. I want to be able to change the body tags and what's inside the head tags and even DTD tags.
Incuding a JavaScript document dynamically (like include() in PHP)

Code: Select all

function include(path)
{
    var newScript = document.createElement('script');
    newScript.type = 'text/javascript';
    newScript.src = path;
    document.getElementsByTagName('head').item(0).appendChild(newScript);
}

include('myscript.js');
How cross browser is that include script you have there??? Excellent idea...I was working on something myself...although I was using a innerHTML not a DOM suggested approach. Turns out IE (I think it was) didn't parse the JS though.

I'll have to try that approach as I read about others suggesting it over innerHTML, but I want absolute browser compatability I don't think old browsers support getElementByTagName, etc

Interesting... :)

Posted: Sun Sep 24, 2006 4:52 pm
by Chris Corbyn
In Opera you need to call include() when the page is fully loaded since the DOM is not initialized (rightly so!). Works in all other browsers. It's a bit RPC'ish becuase the file actually downloads once you apply the src attribute.

Posted: Mon Sep 25, 2006 3:29 am
by n00b Saibot
I always use that method instead of going XMLHTTPRequest way... I suppose this is faster... anyone tested that?

Posted: Mon Sep 25, 2006 4:39 am
by Chris Corbyn
n00b Saibot wrote:I always use that method instead of going XMLHTTPRequest way... I suppose this is faster... anyone tested that?
I imagine it will be much the same since both methods require a request and a response to be dealt with. The only difference as I see it is a readyState check and the initialization of the XMLHttpRequest object. Although I wonder if recent browsers take advantage of XMLHttpRequest transparently to do RPC type stuff.

I'm not all that savvy on benchmarking JS. Any pointers on running speed tests (and it's be great if there way clean ways to to memory usgae tests).