how to actiavate javascript in html - need to install anything?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • happyse27
    New Member
    • Sep 2008
    • 236

    how to actiavate javascript in html - need to install anything?

    Hi all,

    I have enabled Javascripting in internet explorer 7, and I have been writing script in perl.

    The thing I cant do now is to pop up image in small html frame from main html page.... The result of the main html showed blank. Any idea?


    Thanks and Best Rgds,
    Andrew


    a) html script - not sure if the directory perl is correct, put into cgi-bin directory in perl but cant work, so put into d drive...
    =============== ===============

    Code:
    <html> 
       <head> 
         <script src="d:testjava-mod.js"> 
         </script>   
    
       </head> 
    
       <body>
       </body>
    </html>

    javascript(chan ged to d drive from perl default script directory still cannot activate script)
    ========
    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('d:0002.jpg','Temple of Heavenly Bliss', 384, 288,'white')"><IMG SRC="d: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>
  • pronerd
    Recognized Expert Contributor
    • Nov 2006
    • 392

    #2
    The source attribute needs to be a URL or URI. You can not use the local file system path.

    Comment

    • happyse27
      New Member
      • Sep 2008
      • 236

      #3
      Hi Sir,

      Thanks! I have used the URL, still cant work.

      Kindly advise, or rather, any sample to refer to ?? Thanks in advance.


      Cheers...
      Andrew

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Is b) the JavaScript file? It should contain only JavaScript code, not HTML.

        Comment

        • happyse27
          New Member
          • Sep 2008
          • 236

          #5
          same

          Hi Sir,

          I have managed to activate from internet explorer d:testjava-mod.html. Realised that just need to insert javascript into html(see below item a). And the html page showed a rectange, but the actual picture not shown. I have put the picture 0002.jpg into d drive as well. Not sure why the picture not shown?

          But how do I call from a javascript .js file from html item b) syntax below? Got difficulty doing that.
          The format of the javascript file that is called from the html page is how?


          Thanks and Best Rgds,
          Andrew


          a) javascript in html
          ===============
          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>

          b) html to activate javascript
          =============== ======

          Code:
          <html> 
             <head> 
               <script src="/cgi-bin/testjava-mod.js"> 
               </script>   
             </head> 
          
             <body>
             </body>
          </html>
          Last edited by happyse27; Nov 6 '08, 04:53 PM. Reason: typo

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            In b), what are the contents of testjava-mod.js? Is the relative path correct, i.e. is the JavaScript file in the cgi-bin folder relative to the location of the HTML file?

            Comment

            • happyse27
              New Member
              • Sep 2008
              • 236

              #7
              Hi,

              How to do that? I just want to know the sample layout of .js when I call from my above html code? Kindly assist. Thanks.


              Best Rgds,
              Andrew

              Comment

              • gits
                Recognized Expert Moderator Expert
                • May 2007
                • 5390

                #8
                as you see :: acoder asked you a question ... and typically a question requires an answer and not a question in return :) ... basicly he asked you to check whether the location of your included JS-code is correct? is it? in case it is not then fix that first please ... otherwise just confirm that the location is ok ... for a quick test just write an alert to line1 of your javascript-file and have a look whether it is called or not when the page is loaded.

                kind regards

                Comment

                • happyse27
                  New Member
                  • Sep 2008
                  • 236

                  #9
                  Hi Sir,

                  Yes, the path is correct, but 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.


                  a) html
                  =====
                  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

                  <html>
                  <head>
                  <SCRIPT LANGUAGE="JAVAS CRIPT" SRC="j_pop5.js"
                  TYPE="TEXT/JAVASCRIPT">
                  <!--

                  //-->
                  </SCRIPT>
                  </head>

                  <body>
                  </body>
                  </html>


                  javascript
                  =======

                  Code:
                  <script language="JavaScript1.2" type="text/javascript">
                  <!-- ;
                  alert("Welcome to my world!!!");
                  
                  // Based on JavaScript provided by Peter Curtis at www.pcurtis.com -->
                  </script>

                  Comment

                  • gits
                    Recognized Expert Moderator Expert
                    • May 2007
                    • 5390

                    #10
                    the only thing that has to be in the js-file is JavaScript-code ... just leave out those script-tags and the useless html-comments ...

                    regards

                    Comment

                    • gits
                      Recognized Expert Moderator Expert
                      • May 2007
                      • 5390

                      #11
                      i'm closing this thread to let everything go here in this thread ... since now there are to much threads spread in the forum regarding this issue.

                      regards
                      MOD

                      Comment

                      Working...