how to activate javascript(how to write the correct format) from html script

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

    how to activate javascript(how to write the correct format) from html script

    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>
    Last edited by happyse27; Nov 8 '08, 04:04 PM. Reason: to format the codes
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    you just have to cut all the html-tags in the .js-file ... since just JavaScript code has to be in it ...

    regards

    Comment

    • happyse27
      New Member
      • Sep 2008
      • 236

      #3
      Hi Sir,

      Thanks!. I tried, but cant work... Not sure what is the sample java script format when called from html?

      Is it like this below? tried before but cant work. Tried other scripts below and cant work...


      Thanks and best Rgds,
      Andrew

      javascript
      =======
      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>   
        
        </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>

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        have a close look at the following example:

        this is the page where a script is included:

        [HTML]
        <html>
        <head>
        <script type="text/javascript" src="foo.js"/>
        </head>
        <body>
        </body>
        </html>
        [/HTML]
        and this is in the file foo.js:
        Code:
        alert('foo');
        regards

        Comment

        • gits
          Recognized Expert Moderator Expert
          • May 2007
          • 5388

          #5
          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...