Source code...
Moderator: General Moderators
Source code...
In Javascript, what property controls the window/frame's source code?
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Seriously, read up on DOM it's marvelous!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.
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');
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
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.d11wtq wrote:Incuding a JavaScript document dynamically (like include() in PHP)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.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');
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...
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
- n00b Saibot
- DevNet Resident
- Posts: 1452
- Joined: Fri Dec 24, 2004 2:59 am
- Location: Lucknow, UP, India
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
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.n00b Saibot wrote:I always use that method instead of going XMLHTTPRequest way... I suppose this is faster... anyone tested that?
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).