"Nesting" Javascripts? - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

"Nesting" Javascripts?

ThummyThummy Posts: 8Member
[b][red]This message was edited by the Thummy at 2002-6-11 5:13:22[/red][/b][hr]
[b][red]This message was edited by the Thummy at 2002-6-10 14:8:32[/red][/b][hr]
I thought I had a good "Trick".

In my HTML I just include one scriptfile ()

And in this file I refer more files by doing things like:
if(some_cookie_setting){
document.write("");
}else{
document.write("");
}
My IE browser under win98 thinks its ok (and I think its valid too).
But other browsers (and IE on a Mac) don't "get it"?

What to do?
Does someone else knows a way to archive the same effect?





Comments

  • pixelmechpixelmech Posts: 1Member
    WHY do you think this is a "trick" and why do you think its "good"? Why do you want to nest JSs?

    I'm not surprised that some browsers would choke on this. I think that in the end you are making your code less readable and error prone by doing this, but this is only my opinion.

    You may have a good reason which might be interesting to hear for doing this, but I can't think of one nor recommend this practice.

    Best

    Pixelmech

    : [b][red]This message was edited by the Thummy at 2002-6-10 14:8:32[/red][/b][hr]
    : I thought I had a good "Trick".
    :
    : In my HTML I just include one scriptfile ()
    :
    : And in this file I refer more files by doing:
    : document.write("");
    : and
    : document.write("");
    :
    : My IE browser under win98 thinks its ok (and I think its valid too).
    : But other browsers (and IE on a Mac) don't "get it"?
    :
    : What to do?
    : Does someone else knows a way to archive the same effect?
    :
    :
    :
    :

  • ThummyThummy Posts: 8Member
    [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    OK more details...

    I've got a site with lots of extra functionalities.
    These are in different scripts and all together a bit big.

    In my HTML I just include one scriptfile ()
    That:
    - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    if(some_cookie_value){
    document.write("");
    }else{
    document.write("");
    }

    All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???

    Netscape 4.7 does it all right!!!.
    I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.




  • compuchipcompuchip Posts: 273Member
    Don't think it's possible. I think the best solution would be creating a global variable like

    var cookieIsTrue;
    cookieIsTrue = (loginname == "Administrator");

    and then make the functions like this

    function weergeef_menu() {
    if (cookieIsTrue) {
    document.write("Hallo, Administrator. Welke gebruiker wilt u verwijderen?");
    // Some more
    }
    else {
    document.write("Hallo. U mag geen gebruikers wijzigen");
    }
    }

    : [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    : OK more details...
    :
    : I've got a site with lots of extra functionalities.
    : These are in different scripts and all together a bit big.
    :
    : In my HTML I just include one scriptfile ()
    : That:
    : - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    : - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    : if(some_cookie_value){
    : document.write("");
    : }else{
    : document.write("");
    : }
    :
    : All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???
    :
    : Netscape 4.7 does it all right!!!.
    : I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    : I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.
    :
    :
    :
    :
    :

  • ThummyThummy Posts: 8Member
    [b][red]This message was edited by the Thummy at 2002-6-19 5:28:6[/red][/b][hr]
    Hi CompuChip, so your dutch too (das makkelijk, maar ik ga toch maar door in t engels)
    I dont see what your reply has to do with my question? (what is not possible?)
    It's not about "who can do what" or how to show things optionally, nor about programm flow conditions. It's about nesting scripts and the way browsers render their output...

    Dit you look at my Example?

    Greetz Thummy




    : Don't think it's possible. I think the best solution would be creating a global variable like
    :
    : var cookieIsTrue;
    : cookieIsTrue = (loginname == "Administrator");
    :
    : and then make the functions like this
    :
    : function weergeef_menu() {
    : if (cookieIsTrue) {
    : document.write("Hallo, Administrator. Welke gebruiker wilt u verwijderen?");
    : // Some more
    : }
    : else {
    : document.write("Hallo. U mag geen gebruikers wijzigen");
    : }
    : }
    :
    : : [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    : : OK more details...
    : :
    : : I've got a site with lots of extra functionalities.
    : : These are in different scripts and all together a bit big.
    : :
    : : In my HTML I just include one scriptfile ()
    : : That:
    : : - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    : : - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    : : if(some_cookie_value){
    : : document.write("");
    : : }else{
    : : document.write("");
    : : }
    : :
    : : All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???
    : :
    : : Netscape 4.7 does it all right!!!.
    : : I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    : : I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.
    : :
    : :
    : :
    : :
    : :
    :
    :







  • compuchipcompuchip Posts: 273Member
    Yes, I did, and what you wanted to do is not possible as far as I know (but if I'm wrong, please correct me).
    I just gave a possible solution for your problem in the example, which was, that you wanted to include a file based on the value of the cookie.

    : [b][red]This message was edited by the Thummy at 2002-6-19 5:28:6[/red][/b][hr]
    : Hi CompuChip, so your dutch too (das makkelijk, maar ik ga toch maar door in t engels)
    : I dont see what your reply has to do with my question? (what is not possible?)
    : It's not about "who can do what" or how to show things optionally, nor about programm flow conditions. It's about nesting scripts and the way browsers render their output...
    :
    : Dit you look at my Example?
    :
    : Greetz Thummy
    :
    :
    :
    :
    : : Don't think it's possible. I think the best solution would be creating a global variable like
    : :
    : : var cookieIsTrue;
    : : cookieIsTrue = (loginname == "Administrator");
    : :
    : : and then make the functions like this
    : :
    : : function weergeef_menu() {
    : : if (cookieIsTrue) {
    : : document.write("Hallo, Administrator. Welke gebruiker wilt u verwijderen?");
    : : // Some more
    : : }
    : : else {
    : : document.write("Hallo. U mag geen gebruikers wijzigen");
    : : }
    : : }
    : :
    : : : [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    : : : OK more details...
    : : :
    : : : I've got a site with lots of extra functionalities.
    : : : These are in different scripts and all together a bit big.
    : : :
    : : : In my HTML I just include one scriptfile ()
    : : : That:
    : : : - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    : : : - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    : : : if(some_cookie_value){
    : : : document.write("");
    : : : }else{
    : : : document.write("");
    : : : }
    : : :
    : : : All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???
    : : :
    : : : Netscape 4.7 does it all right!!!.
    : : : I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    : : : I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : :
    :
    :
    :
    :
    :
    :
    :
    :

  • ThummyThummy Posts: 8Member
    [b][red]This message was edited by the Thummy at 2002-6-19 8:17:24[/red][/b][hr]
    I'll correct you (like you asked for "if you were wrong"): It is very possible (to do what you THINK I wanna do: Including a file based on "whatever"). I already do it all the time! But: If I include a nested file (based on a cookie or something else) I can do all things, except that a document.write() gives his output AFTER the closing of my initial file's tag, not at the place the nested file is included. (I agree, a minor problem, but I'm looking for a fix for THAT)

    Still very thnx for replying, in the process of making myself clear (rephrasing the problem over and over) I now think I know the answer to my own question...lol..;-)
    Greetz Thummy
    : Yes, I did, and what you wanted to do is not possible as far as I know (but if I'm wrong, please correct me).
    : I just gave a possible solution for your problem in the example, which was, that you wanted to include a file based on the value of the cookie.
    :
    : : [b][red]This message was edited by the Thummy at 2002-6-19 5:28:6[/red][/b][hr]
    : : Hi CompuChip, so your dutch too (das makkelijk, maar ik ga toch maar door in t engels)
    : : I dont see what your reply has to do with my question? (what is not possible?)
    : : It's not about "who can do what" or how to show things optionally, nor about programm flow conditions. It's about nesting scripts and the way browsers render their output...
    : :
    : : Dit you look at my Example?
    : :
    : : Greetz Thummy
    : :
    : :
    : :
    : :
    : : : Don't think it's possible. I think the best solution would be creating a global variable like
    : : :
    : : : var cookieIsTrue;
    : : : cookieIsTrue = (loginname == "Administrator");
    : : :
    : : : and then make the functions like this
    : : :
    : : : function weergeef_menu() {
    : : : if (cookieIsTrue) {
    : : : document.write("Hallo, Administrator. Welke gebruiker wilt u verwijderen?");
    : : : // Some more
    : : : }
    : : : else {
    : : : document.write("Hallo. U mag geen gebruikers wijzigen");
    : : : }
    : : : }
    : : :
    : : : : [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    : : : : OK more details...
    : : : :
    : : : : I've got a site with lots of extra functionalities.
    : : : : These are in different scripts and all together a bit big.
    : : : :
    : : : : In my HTML I just include one scriptfile ()
    : : : : That:
    : : : : - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    : : : : - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    : : : : if(some_cookie_value){
    : : : : document.write("");
    : : : : }else{
    : : : : document.write("");
    : : : : }
    : : : :
    : : : : All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???
    : : : :
    : : : : Netscape 4.7 does it all right!!!.
    : : : : I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    : : : : I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.
    : : : :
    : : : :
    : : : :
    : : : :
    : : : :
    : : :
    : : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    :
    :





  • compuchipcompuchip Posts: 273Member
    Obviously, there was some kind of misunderstanding, but anyway, the problem is solved.

    Have programming fun!

    : [b][red]This message was edited by the Thummy at 2002-6-19 8:17:24[/red][/b][hr]
    : I'll correct you (like you asked for "if you were wrong"): It is very possible (to do what you THINK I wanna do: Including a file based on "whatever"). I already do it all the time! But: If I include a nested file (based on a cookie or something else) I can do all things, except that a document.write() gives his output AFTER the closing of my initial file's tag, not at the place the nested file is included. (I agree, a minor problem, but I'm looking for a fix for THAT)
    :
    : Still very thnx for replying, in the process of making myself clear (rephrasing the problem over and over) I now think I know the answer to my own question...lol..;-)
    : Greetz Thummy
    : : Yes, I did, and what you wanted to do is not possible as far as I know (but if I'm wrong, please correct me).
    : : I just gave a possible solution for your problem in the example, which was, that you wanted to include a file based on the value of the cookie.
    : :
    : : : [b][red]This message was edited by the Thummy at 2002-6-19 5:28:6[/red][/b][hr]
    : : : Hi CompuChip, so your dutch too (das makkelijk, maar ik ga toch maar door in t engels)
    : : : I dont see what your reply has to do with my question? (what is not possible?)
    : : : It's not about "who can do what" or how to show things optionally, nor about programm flow conditions. It's about nesting scripts and the way browsers render their output...
    : : :
    : : : Dit you look at my Example?
    : : :
    : : : Greetz Thummy
    : : :
    : : :
    : : :
    : : :
    : : : : Don't think it's possible. I think the best solution would be creating a global variable like
    : : : :
    : : : : var cookieIsTrue;
    : : : : cookieIsTrue = (loginname == "Administrator");
    : : : :
    : : : : and then make the functions like this
    : : : :
    : : : : function weergeef_menu() {
    : : : : if (cookieIsTrue) {
    : : : : document.write("Hallo, Administrator. Welke gebruiker wilt u verwijderen?");
    : : : : // Some more
    : : : : }
    : : : : else {
    : : : : document.write("Hallo. U mag geen gebruikers wijzigen");
    : : : : }
    : : : : }
    : : : :
    : : : : : [b][red]This message was edited by the Thummy at 2002-6-11 12:42:10[/red][/b][hr]
    : : : : : OK more details...
    : : : : :
    : : : : : I've got a site with lots of extra functionalities.
    : : : : : These are in different scripts and all together a bit big.
    : : : : :
    : : : : : In my HTML I just include one scriptfile ()
    : : : : : That:
    : : : : : - Generates a (hideable) form where a visitor can set options that are stored in a cookie.
    : : : : : - Reads the cookie at next visit, or a reload, and then I refer more files by doing things like:
    : : : : : if(some_cookie_value){
    : : : : : document.write("");
    : : : : : }else{
    : : : : : document.write("");
    : : : : : }
    : : : : :
    : : : : : All functions can be called, but a "inline" document.write() now "gives his result" a lot lower in the page then it should. In my IE beneath the table the cell is in that "holds" my script. In IE on a Mac it appears at the total bottom of the page???
    : : : : :
    : : : : : Netscape 4.7 does it all right!!!.
    : : : : : I'm getting to think by now it's an IE bug, I can't change that, so the initial question still stands, does someone knows another way to archive the include effect I need?
    : : : : : I made a test/proof, very minimal, only contains the "bug", go http://www.xs4all.nl/~thummy/nested/nested.html for a view.
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : : :
    : : : :
    : : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : : :
    : :
    : :
    :
    :
    :
    :
    :
    :

Sign In or Register to comment.