Web Analytics Made Easy -
StatCounter Script execution problem in all browsers except in Opera - CodingForum

Announcement

Collapse
No announcement yet.

Script execution problem in all browsers except in Opera

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Script execution problem in all browsers except in Opera

    I use an external .js file for menu genaration. It works, except when I have another Javascript code in the same page (here the coding is within the page itself). Now the script coded within the page executes but the other one which refers to the .js files doesn't execute. No error is reported. This phenomenon is with all browsers (IE6, NS7.1, MOZILLA1.5 etc.) except one. The Opera7 executes both the scripts.

    How can I execute both the scripts in these browsers as well?

    Regards,
    ATC & Programming - Coupled Passions

  • #2
    If we don't see the codes we can't say why this happens.

    Usually, the second script woun't work if both scripts have functions fired by the onload event handler in separate lines (with other words, you have two (or more) onload event handlers. That can be solved, but let's see your scripts first (if too large, better an URL or an attachment would be fine)
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

    Comment


    • #3
      Thanks Kor, u r a dear. The two codes are:

      SCRIPT I
      <script type='text/javascript'>
      function Go(){return}
      </script>
      <script type='text/javascript' src='exmplmenu_var.js'></script>
      <script type='text/javascript' src='menu_com.js'></script>
      <noscript>Your browser does not support script</noscript>

      SCRIPT II
      <script>
      function openpopup(){
      var popurl="discfrmpopup.asp"
      winpops=window.open(popurl,"","width=210,height=60,")
      }
      openpopup()
      </script>

      The scripts are in order of their appearance in the page. The second script works but not the first one in all browsers except Opera where both the scripts work.

      I am attaching the page containing the code.
      ATC & Programming - Coupled Passions

      Comment


      • #4
        Sorry, the attachment is with this post
        Attached Files
        ATC & Programming - Coupled Passions

        Comment


        • #5
          I see no attachment
          KOR
          Offshore programming
          -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

          Comment


          • #6
            Still I don't understand how many scripts are. And I still have no

            'exmplmenu_var.js'
            'menu_com.js'

            Anyway, I see that you want to open a popup... Well, i don't see which is the event to fire the function... You want it to be open onload? This case you must have:

            <script>
            function openpopup(){
            var popurl="discfrmpopup.asp";
            winpops=window.open(popurl,"","width=210,height=60");
            }
            </script>

            and fire this function on marquee's onload handled function:

            function populate(){
            if (iedom){
            cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
            cross_marquee.style.left=parseInt(marqueewidth)+8+"px"
            cross_marquee.innerHTML=marqueecontent
            actualwidth=document.all? temp.offsetWidth : document.getElementById("temp").offsetWidth
            }
            else if (document.layers){
            ns_marquee=document.ns_marquee.document.ns_marquee2
            ns_marquee.left=parseInt(marqueewidth)+8
            ns_marquee.document.write(marqueecontent)
            ns_marquee.document.close()
            actualwidth=ns_marquee.document.width
            }
            lefttime=setInterval("scrollmarquee()",20);
            open popup();
            }
            KOR
            Offshore programming
            -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

            Comment


            • #7
              remove the empty space between open and popup()....
              KOR
              Offshore programming
              -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

              Comment


              • #8
                The problem is not with the popup, it is the menu scripts. The popup opens on all browsers.

                Attached is the 1st .js script
                The 2nd .js script is attached with the next post
                Attached Files
                ATC & Programming - Coupled Passions

                Comment


                • #9
                  here's the other .js script
                  Attached Files
                  ATC & Programming - Coupled Passions

                  Comment


                  • #10
                    To avoid "multiple onload" problem, take care about some essentials:

                    1. Except for few special functions (alert, prompt...) to run, any javascript function must be fired, called, by an event handler (onload, onclick, onmouseover, onkeyp and so on... see a list on a tutorial).

                    2. The onload event handler is a particular one, it applies only over the window object. As the window is an unique object, onload can not be used more than once on a page. There are some ways to write it:

                    <script>
                    function bla(){
                    .........
                    }
                    </script>
                    ...
                    <body onload="bla()">

                    or-------

                    <script>
                    function bla(){
                    .........
                    }
                    window.onload = bla;
                    </script>

                    or-------

                    <script>
                    function bla(){
                    .........
                    }
                    window.onload = function(){bla()}
                    </script>

                    or even (useful for a multimple call)

                    <script>
                    function bla(){
                    .........
                    }
                    function init(){
                    bla();
                    }
                    window.onload = init;
                    </script>

                    3. Now, if you use more codes, more scripts, it might be possible that each script have his own onload event handler. If so, erase all the onload events from scripts and use it once in body:

                    <body onload = "bla1();bla2();bla3()">

                    or keep only in one of the scripts, nomatter which, and build there something like

                    ....
                    function init(){
                    bla1();
                    bla2();
                    bla3()
                    }
                    window.onload = init;
                    </script>
                    KOR
                    Offshore programming
                    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                    Comment


                    • #11
                      thanks, i understand; but the problem is my scripts cannot be fired from the onload event handler as they must execute only if the first two if...elseif... conditions are not satisfied.

                      Let me describe a bit...

                      Following is the condition which is checked first...
                      <%
                      Dim Conn
                      Dim RSUser
                      Dim Last
                      Dim varUserID
                      Dim varPassword
                      Set Conn = Server.CreateObject("ADODB.Connection")
                      Set RSUser = Server.CreateObject("ADODB.Recordset")
                      varUserID = Replace(Request.Form("UserID"), "'", "''")
                      varPassword = Replace(Request.Form("Password"), "'", "''")
                      Conn.Open "database"
                      SQL = "Select * from Members Where UserID='" & varUserID & "'"
                      RSUser.Open SQL,Conn,2,3
                      If RSUser.EOF Then
                      %>
                      .......
                      The scripts should NOT fire if the above condition is satisfied.

                      The second condition which is checked is...
                      ...
                      <%
                      ElseIf RSUser("Password") <> varPassword Then
                      %>
                      ...
                      Again the scripts should NOT fire if the above condition is satisfied

                      Only if the above two conditions are not satisfied then only the scripts should fire:
                      ...
                      <%
                      Else
                      Email=RSUser("Email")
                      Session("User") = "Yes"
                      Session("UserID") = varUserID
                      session.timeout=20
                      %>
                      ....
                      The scripts should fire now.

                      I hope I am able to clarify to your satisfaction.
                      ATC & Programming - Coupled Passions

                      Comment


                      • #12
                        If you have <body onload> and window.onload, Opera 7 fires them both; in all other browsers, window.onload overrides body onload.

                        Why not ditch those methods and use addEventListener and attachEvent insteadd.
                        "Why bother with accessibility? ... Because deep down you know that the web is attractive to people who aren't exactly like you." - Joe Clark

                        Comment


                        • #13
                          <%....

                          %>

                          are not javascript code lines... I don't know what to say....
                          KOR
                          Offshore programming
                          -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

                          Comment


                          • #14
                            They are ASP script tags. The contents are scripts to be executed serverside.
                            liorean <[[email protected]]>
                            Articles: RegEx evolt wsabstract , Named Arguments
                            Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
                            Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

                            Comment

                            Working...
                            X