how to activate javascript file from html page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • happyse27
    New Member
    • Sep 2008
    • 236

    how to activate javascript file from html page

    Hi All,

    The html page(see item a below) is calling javascript(item b below), but cant work as the page show blank. Not sure if the method of calling is wrong(in terms of default directory) or javascript is wrong.

    using 127.0.0.1/htmlscript.html below to call the java script embedded in the following html script.

    I am using apache server and apache server have error 304(not modified)

    Been trying many methods for past 1 week...

    Not sure where went wrong?

    Thanks and Best Rgds,
    Andrew

    a) html page
    =========

    Code:
    <html> 
       <head>
    <SCRIPT LANGUAGE="JAVASCRIPT" SRC="j_pop4.js"
    TYPE="TEXT/JAVASCRIPT">
    <!--
    
    //-->
    </SCRIPT>
     </head> 
    
       <body>
       </body>
    </html>
    b) javascript
    =========

    Code:
    <html>  
       <head>  
    <TITLE>Java Popup Window Example with size, title and background colour parameters</TITLE> 
    <script language="JavaScript1.2" type="text/javascript"> 
    <!-- ; 
    var newwindow; 
    var wheight = 0, wwidth = 0; 
      
    function popitup5(url, title, iwidth, iheight, colour) { 
    var pwidth, pheight; 
      
    if ( !newwindow || newwindow.closed ) { 
    pwidth=iwidth+30; 
    pheight=iheight+30; 
    newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10'); 
    wheight=iheight; 
    wwidth=iwidth; 
    } 
      
    if (wheight!=iheight || wwidth!=iwidth ) { 
    pwidth=iwidth+30; 
    pheight=iheight+90; 
    newwindow.resizeTo(pwidth, pheight); 
    wheight=iheight; 
    wwidth=iwidth; 
    } 
      
    newwindow.document.clear(); 
    newwindow.focus(); 
    newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>'); 
    newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >'); 
    newwindow.document.writeln('<\/center> <\/body> <\/html>'); 
    newwindow.document.close(); 
    newwindow.focus(); 
    } 
      
    // Routines to tidy up popup windows when page is left 
    // Call with an onUnload="tidy5()" in body tag 
      
    function tidy5() { 
    if (newwindow && !newwindow.closed) { newwindow.close(); } 
    } 
      
    // Based on JavaScript provided by Peter Curtis at www.pcurtis.com --> 
    </script> 
      
      </head>  
      
    <BODY onUnload="tidy5()" >  
      
    <A HREF="javascript:popitup5('0002.jpg','Temple of Heavenly Bliss', 384, 288,'white')"><IMG SRC="0002.jpg" WIDTH="160" BORDER="0" HEIGHT="120" HSPACE="10" VSPACE="5" ALT="Temple of Heavenly Bliss" TITLE="Temple of Heavenly Bliss" ALIGN=left></A>  
      
      
      
       </body> 
    </html>
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    you may find your answer here ... in the JavaScript forum.

    regards

    Comment

    • David Laakso
      Recognized Expert Contributor
      • Aug 2008
      • 397

      #3
      Originally posted by gits
      you may find your answer here ... in the JavaScript forum.

      regards
      And a doctype will be needed (if you intend to support any version of Internet Explorer).

      Comment

      • happyse27
        New Member
        • Sep 2008
        • 236

        #4
        how to activate javascript file from html page

        Hi Sir,

        Read the java weblink you gave and ,

        Is it something like that below? tried many times and different ways, used html to activate javascript and it did not work. and used html to activate java embedded in html page, but cant work.

        Thanks and Best Rgds,
        Andrew

        HTML
        ====
        Code:
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
        
        <html> 
           <head>
        <SCRIPT LANGUAGE="JAVASCRIPT" SRC="j_pop4.js"
        TYPE="TEXT/JAVASCRIPT">
        <!--
        
        //-->
        </SCRIPT>
         </head> 
        
           <body>
           </body>
        </html>

        JAVAscript that is activated
        =============== =====
        Code:
        <TITLE>Java Popup Window Example with size, title and background colour parameters</TITLE>
        <script language="JavaScript1.2" type="text/javascript">
        <!-- ;
        var newwindow;
        var wheight = 0, wwidth = 0;
        
        function popitup5(url, title, iwidth, iheight, colour) {
        var pwidth, pheight;
        
        if ( !newwindow || newwindow.closed ) {
        pwidth=iwidth+30;
        pheight=iheight+30;
        newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
        wheight=iheight;
        wwidth=iwidth;
        }
        
        if (wheight!=iheight || wwidth!=iwidth ) {
        pwidth=iwidth+30;
        pheight=iheight+90;
        newwindow.resizeTo(pwidth, pheight);
        wheight=iheight;
        wwidth=iwidth;
        }
        
        newwindow.document.clear();
        newwindow.focus();
        newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
        newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >');
        newwindow.document.writeln('<\/center> <\/body> <\/html>');
        newwindow.document.close();
        newwindow.focus();
        }
        
        // Routines to tidy up popup windows when page is left
        // Call with an onUnload="tidy5()" in body tag
        
        function tidy5() {
        if (newwindow && !newwindow.closed) { newwindow.close(); }
        }
        
        // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->
        </script>
        
        
        
        
        <A HREF="javascript:popitup5('0002.jpg','Temple of Heavenly Bliss', 384, 288,'white')"><IMG SRC="0002.jpg" WIDTH="160" BORDER="0" HEIGHT="120" HSPACE="10" VSPACE="5" ALT="Temple of Heavenly Bliss" TITLE="Temple of Heavenly Bliss" ALIGN=left></A> 
        
        
        
        #The code can be copied and pasted. If you copy by hand beware as it is impossible to tell 2x single quotes '' from a double quotes " in many proportion spaced character sets (fonts).
        Last edited by happyse27; Nov 9 '08, 03:30 AM. Reason: include the javascript heading for clarity of explanation..

        Comment

        • happyse27
          New Member
          • Sep 2008
          • 236

          #5
          Hi Sir,

          Something is missing and I tried many different ways and means including alert and still cant work. Please see below a)html and b)javascript. I activated the js script from default apache directory which is htdocs directory where I placed the javascript if you refer the my html above.

          Installed IE6


          a) html
          =====
          Code:
          <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 
          
          <html> 
          <head>
          <SCRIPT LANGUAGE="JAVASCRIPT" SRC="j_pop5.js"
          TYPE="TEXT/JAVASCRIPT">
          <!--
          
          //-->
          </SCRIPT>
          </head> 
          
          <body>
          </body>
          </html>

          javascript
          =======

          Code:
          Expand|Select|Wrap|Line Numbers <script language="JavaScript1.2" type="text/javascript"> 
          <!-- ; 
          alert("Welcome to my world!!!");

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5390

            #6
            there is nothing missing ... it is just too much ... leave the script-tags out and drop those useless comment ... just the alert() should be left in the JS-file ... here is an example ...

            regards

            Comment

            • Markus
              Recognized Expert Expert
              • Jun 2007
              • 6092

              #7
              --Moved to Javascript.

              Another thing to note: everything should be lowercase if you wish to comply with HTML standards. The 'language' attribute is deprecated (not needed or supported).

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                hi happyse27,

                i just closed the following threads that are handling the same issue:




                please try to keep one thread for a specific problem ... since otherwise it would lead to just spreaded information and answers ... i don't feel like merging all the threads since some different lines of code are posted there and some different hints and answers but as far as i could see the problem is always the same and so we should just use this thread here. i linked everything together so we could jump from thread to thread.

                kind regards
                MOD

                Comment

                • happyse27
                  New Member
                  • Sep 2008
                  • 236

                  #9
                  Hi Sir,

                  Thanks and noted, sorry and apologize because I did that because I dont know if it belongs to javascript issue or html's therefore did double post. Anyway, I tried your method. But still the alert message below did not pop up... Checked apache access log is it error 500 and error 543. Kindly advise what is happening???


                  The example you given..
                  =============== ==
                  this is the page where a script is included:
                  Code:
                  <html> 
                      <head> 
                          <script type="text/javascript" src="foo.js"/> 
                      </head> 
                      <body> 
                      </body> 
                  </html>
                  and this is in the file foo.js:
                  Code:
                  alert('foo');
                  Error from apache access if I put javapop.js into apache/cgi-bin directory
                  =============== =============== =============== ==
                  127.0.0.1 - - [09/Nov/2008:22:00:28 -0800] "GET /javapop.html HTTP/1.1" 304 -
                  127.0.0.1 - - [09/Nov/2008:22:00:28 -0800] "GET /cgi-bin/javapop.js HTTP/1.1" 500 543

                  Error from apache access if I put javapop.js into apache/htdocs directory
                  =============== =============== =============== ==
                  127.0.0.1 - - [09/Nov/2008:21:56:24 -0800] "GET /javapop.html HTTP/1.1" 304 -
                  127.0.0.1 - - [09/Nov/2008:21:56:24 -0800] "GET /javapop.js HTTP/1.1" 304 -

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    just clear your browser cache first and try the second method again ... does the files just contain the example?

                    Comment

                    • waltapp
                      New Member
                      • Nov 2008
                      • 31

                      #11
                      Here is the code you need. It needs to be nested inside the head element.
                      <head>
                      <script src="anyfile.js " type="text/javascript"></script>
                      </head>

                      Also do not forget to close the Script and pay attention to capitals or non.

                      Comment

                      • happyse27
                        New Member
                        • Sep 2008
                        • 236

                        #12
                        Hi Sirs,

                        Thanks!!!!!!!!! !!!!! It works. Activated from html the .js file. Cheers...

                        </script> was missing. Cheers...


                        Best Rgds,
                        Andrew

                        Comment

                        • happyse27
                          New Member
                          • Sep 2008
                          • 236

                          #13
                          Hi All,

                          I activated another script from the similar html page(see item a) below. Cant work. Taken out the html tag in .js file still did not work. Not sure where is the problem??


                          Thanks again,
                          Andrew


                          html code
                          =======
                          Code:
                          html>
                              <head> 
                                  <script type="text/javascript" src="javapop2.js"/> </script>
                              </head> 
                              <body> 
                              </body> 
                          </html>

                          javascript
                          =======

                          Code:
                          <HTML>
                          <HEAD>
                          <TITLE>Java Popup Window Example with size, title and background colour parameters</TITLE>
                          <script language="JavaScript1.2" type="text/javascript">
                          <!-- ;
                          var newwindow;
                          var wheight = 0, wwidth = 0;
                          
                          function popitup5(url, title, iwidth, iheight, colour) {
                          var pwidth, pheight;
                          
                          if ( !newwindow || newwindow.closed ) {
                          pwidth=iwidth+30;
                          pheight=iheight+30;
                          newwindow=window.open('','htmlname','width=' + pwidth +',height=' +pheight + ',resizable=1,top=50,left=10');
                          wheight=iheight;
                          wwidth=iwidth;
                          }
                          
                          if (wheight!=iheight || wwidth!=iwidth ) {
                          pwidth=iwidth+30;
                          pheight=iheight+90;
                          newwindow.resizeTo(pwidth, pheight);
                          wheight=iheight;
                          wwidth=iwidth;
                          }
                          
                          newwindow.document.clear();
                          newwindow.focus();
                          newwindow.document.writeln('<html> <head> <title>' + title + '<\/title> <\/head> <body bgcolor= \"' + colour + '\"> <center>');
                          newwindow.document.writeln('<img src=' + url + ' title=\"' + title + '\" alt=\"' + title + '\" >');
                          newwindow.document.writeln('<\/center> <\/body> <\/html>');
                          newwindow.document.close();
                          newwindow.focus();
                          }
                          
                          // Routines to tidy up popup windows when page is left
                          // Call with an onUnload="tidy5()" in body tag
                          
                          function tidy5() {
                          if (newwindow && !newwindow.closed) { newwindow.close(); }
                          }
                          
                          // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->
                          </script>
                          
                          
                          </HEAD> 
                          
                          <BODY onUnload="tidy5()" > 
                          
                          <A HREF="javascript:popitup5('0002.jpg','Temple of Heavenly Bliss', 384, 288,'white')"><IMG SRC="0002.jpg" WIDTH="160" BORDER="0" HEIGHT="120" HSPACE="10" VSPACE="5" ALT="Temple of Heavenly Bliss" TITLE="Temple of Heavenly Bliss" ALIGN=left></A> 
                          
                          </BODY>
                          </HTML>

                          Comment

                          • Markus
                            Recognized Expert Expert
                            • Jun 2007
                            • 6092

                            #14
                            This thread is confusing me greatly.

                            You say the second part of the code in your most recent post is the javascript file? If so, there can be NO html in there whatsoever. You need not the opening and closing javascript elements, either.

                            Comment

                            • gits
                              Recognized Expert Moderator Expert
                              • May 2007
                              • 5390

                              #15
                              it confuses me too ... first:

                              this:

                              [HTML]<script type="text/javascript" src="javapop2.j s"/></script>[/HTML]
                              is simply wrong, either use:

                              [HTML]<script type="text/javascript" src="javapop2.j s"></script>
                              [/HTML]
                              or:

                              [html]<script type="text/javascript" src="javapop2.j s"/>[/html]
                              together with a proper doctype. and every file that you post as a javascript-file is in fact a html-file ... should we always tell you to leave out all html in those files?

                              regards

                              Comment

                              Working...