The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> interesting error with including documents
CodeKing
post Dec 19 2007, 07:50 PM
Post #1


Advanced Member
****

Group: Members
Posts: 175
Joined: 12-September 06
Member No.: 118



CODE

index.html:

...<script type="text/javascript" src="boxle/boxle.js">
<!-- -->
</script>...


CODE

boxle.js:

window.onload = function() { //What to do when the document loads
    alert("Config loaded");
    bx_include("boxle/config.js");
}

function bx_include(script_filename) {
    document.writeln('<' + 'script');
    document.writeln(' language="javascript"');
    document.writeln(' type="text/javascript"');
    document.writeln(' src="' + script_filename + '">');
    document.writeln('<\/' + 'script' + '>');
}


As soon as I hit OK to the alert box the content on the page disappears. What am I doing wrong?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CodeKing
post Dec 19 2007, 10:15 PM
Post #2


Advanced Member
****

Group: Members
Posts: 175
Joined: 12-September 06
Member No.: 118



You can view it HERE.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Dec 19 2007, 10:52 PM
Post #3


Jocular coder
********

Group: Members
Posts: 2,298
Joined: 31-August 06
Member No.: 43



QUOTE(CodeKing @ Dec 20 2007, 09:50 AM) *

CODE

index.html:

...<script type="text/javascript" src="boxle/boxle.js">
<!-- -->
</script>...


CODE

boxle.js:

window.onload = function() { //What to do when the document loads
    alert("Config loaded");
    bx_include("boxle/config.js");
}

function bx_include(script_filename) {
    document.writeln('<' + 'script');
    document.writeln(' language="javascript"');
    document.writeln(' type="text/javascript"');
    document.writeln(' src="' + script_filename + '">');
    document.writeln('<\/' + 'script' + '>');
}


As soon as I hit OK to the alert box the content on the page disappears. What am I doing wrong?



Obviously! Where do you hope that the content produced by bx_include() will be written? The function is not run until after the page has loaded, so any subsequent document.write() - and I presume writeln() is the same - will start writing a new document.

What are you actually trying to do?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CodeKing
post Dec 20 2007, 09:00 PM
Post #4


Advanced Member
****

Group: Members
Posts: 175
Joined: 12-September 06
Member No.: 118



Got it all fixed, and it works. Unfortunately, there's a weird error in IE 7 where it displays "<div id="bx_container>Boxle container set up nicely" instead of "Boxle container set up nicely"

This is the source the javascript generates
CODE

<script language="javascript" type="text/javascript" src="/javascript/boxle/config.js">
</script><script language="javascript" type="text/javascript" src="/javascript/boxle/debug.js">
</script><div id="bx_debug_console"><p>"config.js" has been included successfully.</p><p>"debug.js" has been included successfully.</p></div><div id="bx_css_style_test">There was an error writing the CSS stylesheet</div><div id="bx_container">Boxle container set up nicely</div>


It looks fine to me.
Any help?

Once again, you can view the whole thing at http://www.mostmojo.com/projects/boxle/

This post has been edited by CodeKing: Dec 20 2007, 09:00 PM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Frederiek
post Dec 21 2007, 03:42 AM
Post #5


Programming Fanatic
********

Group: Members
Posts: 5,146
Joined: 23-August 06
From: Europe
Member No.: 9



FYI, I get a blank page in Safari 3/Mac.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Dec 21 2007, 07:54 AM
Post #6


Jocular coder
********

Group: Members
Posts: 2,298
Joined: 31-August 06
Member No.: 43



QUOTE
It looks fine to me.Any help?


When I view the URL you've given, I see a plain white page with the mysterious message:

<div id="bx_container>

Is that what a "non-intrusive notification script" looks like?

I can make no sense at all of your Javascript files. You call a function, which simply calls another function, which simply calls another function; what for?

What is the following function supposed to do?

function bx_include(script_filename) {
document.writeln('<' + 'script');
document.writeln(' language="javascript"');
document.writeln(' type="text/javascript"');
document.writeln(' src="' + script_filename + '">');
document.writeln('<\/' + 'script' + '>');
}

OK, it writes:

<script language="javascript" type="text/javascript" src="*FILE*"></script>

into the current document, with the addition of lots of newlines[???], but what should this do? Do you think (after all, you're the Codeking) that if the output of write() looks a bit like Javascript the Javascript interpreter should somehow reparse the program it's running at the moment with the added bits?

Can you clarify what "It looks fine" means? Do you mean that it looks to you as though this program should do something? Or do you mean you have a browser in which it appears to work?

This post has been edited by Brian Chandler: Dec 21 2007, 07:56 AM
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 26th March 2019 - 01:30 PM