Source code...

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Source code...

Post by JellyFish »

In Javascript, what property controls the window/frame's source code?
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

What part of it? What are you trying to control?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

The source code. Example, window.sourceCode = "Anyhtml I want";
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

JellyFish wrote:The source code. Example, window.sourceCode = "Anyhtml I want";
document.body.innerHTML ?
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

Yeah maybe. I'm not sure.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

hmm... try it maybe? :roll: :lol:
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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;
    }
}
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post 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... :)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

I always use that method instead of going XMLHTTPRequest way... I suppose this is faster... anyone tested that?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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).
Post Reply