Web Analytics Made Easy -
StatCounter Always Visible Combo Box, a question - CodingForum

Announcement

Collapse
No announcement yet.

Always Visible Combo Box, a question

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

  • Always Visible Combo Box, a question

    I have a web site with 18 pages, i want to add a combo box to all of them to make browsing easier so i decided to put the Always Visible Combo Box to all of them. However i dont want to paste the long code to all the pages, i want to create a .js file and launch the external js.

    How do i do that?

  • #2
    Save the contents of a script tag to a separate file with a .js extension.
    Then use a script tag containing the name of the .js file.

    This code (myPage.html)
    Code:
    <html>
      <head>
        <title>My Page</title>
        <script type="text/javascript"><!--
          function myFunction(){
              //do something.
          }
        //--></script>
      </head>
      <body>
        <h1>My Page</h1>
      </body>
    </html>
    Becomes two files:
    (myPage.html)
    Code:
    <html>
      <head>
        <title>My Page</title>
        <script type="text/javascript" src="myScript.js"></script>
      </head>
      <body>
        <h1>My Page</h1>
      </body>
    </html>
    (myScript.js)
    Code:
    function myFunction(){
      //do something.
    }

    Comment


    • #3
      It isnt working.

      This is the exact code:

      <span id="staticcombo" style="position:absolute;left:0;top:0;visibility:hidden">
      <form name="jumpy">
      <p><select name="example" size="1" onChange="gone()">
      <option value="http://www.freewarejava.com">Freewarejava.com</option>
      <option value="http://www.dynamicdrive.com">Dynamic Drive</option>
      <option value="http://www.codingforum.net">codingforum.net</option>
      <option value="http://www.news.com">News.com</option>
      </select>

      <script language="javascript">
      <!--

      /*
      Always-visible combo box credit:
      JavaScript Kit (http://www.javascriptkit.com)
      Over 400+ free JavaScripts here! (keep this credit intact)
      */

      //enter "" for current window, "_new" for new window", or "framename" for name of frame
      var linktarget=""

      function gone(){
      if (linktarget=="")
      location=document.jumpy.example.options[document.jumpy.example.selectedIndex].value
      else if (linktarget=="_new")
      window.open(document.jumpy.example.options[document.jumpy.example.selectedIndex].value)
      else{
      targetobj=eval("window.parent."+linktarget)
      targetobj.location=document.jumpy.example.options[document.jumpy.example.selectedIndex].value
      }
      }
      //-->
      </script>

      <input type="button" name="test" value="Go!"
      onClick="gone()">
      </p>
      </form>
      </span>


      <script language="JavaScript1.2">

      function initialize(){
      comboobj=document.all? document.all.staticcombo : document.getElementById? document.getElementById("staticcombo") : document.layers? document.staticcombo : 0

      windowwidth=window.innerWidth? window.innerWidth-30 : document.body.clientWidth-20
      windowheight=window.innerHeight? window.innerHeight : document.body.clientHeight

      if (!comboobj)
      return

      if (document.all || document.getElementById){
      combowidth=comboobj.offsetWidth
      comboheight=comboobj.offsetHeight
      setInterval("staticit_dom()",50)
      comboobj.style.visibility="visible"
      }
      else if (document.layers){
      combowidth=comboobj.document.width
      comboheight=comboobj.document.height
      setInterval("staticit_ns()",50)
      comboobj.visibility="show"
      }
      }

      function staticit_dom(){
      var pageoffsetx=document.all? document.body.scrollLeft : window.pageXOffset
      var pageoffsety=document.all? document.body.scrollTop : window.pageYOffset

      comboobj.style.left=pageoffsetx+windowwidth-combowidth
      comboobj.style.top=pageoffsety+windowheight-comboheight
      }

      function staticit_ns(){
      comboobj.left=pageXOffset+windowwidth-combowidth
      comboobj.top=pageYOffset+windowheight-comboheight
      }

      window.onload=initialize
      </script>

      I tired to put the first paragraph to the .htm file also, but it didnt work either

      Comment

      Working...
      X