Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25189

Re: external javascript menu - highlight current page

Newsgroups comp.lang.javascript
Subject Re: external javascript menu - highlight current page
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <b82c2a70-e44f-4166-bd3a-727fac2dbf3a@googlegroups.com>
Date 2014-07-02 11:48 +0200
Message-ID <XnsA35E782066C39eejj99@194.109.133.133> (permalink)

Show all headers | View raw


ba pal <bpascal362@gmail.com> wrote on 02 jul 2014 in
comp.lang.javascript: 

> My website works using a javascript menu in an external file like the
> following 

Your code looks like JS from the last century,
before anyone had ever heard of CSS and Regex.

 
> The javascript JsMenuShowFile.js
> ----------------------------------
> function JsMenuShow(){
>      document.write('<ul>');
>      document.write('<li id="Li_style1"><a id="a_style1"
>      href="link1_item.html">link1 page</a></li>'); document.write('<li
>      id="Li_style1"><a id="a_style1" href="link2_item.html">link2
>      page</a></li>');     document.write('</ul>');
>      document.write('<li id="Li_style1"><a id="a_style1"
>      href="link3_item.html">link3 page</a></li>');     
>      document.write('</ul>'); return this;
>}

btw, why the "return this" ?

Why not just forget about the overhead 
of external loading and do:

===========================================
<ul style='display;none;' id='myMenu'>
[...]
</ul>

if( /link[12]_item\.html/.test(location.href) ){
   document.getElementById('myMenu').style.display =
     'block';   
};
============================================

[Or if you really want an external file, 
use serverside includes, and/or full serverside code?]

> if(document.URL.indexOf("link1_item.html")!=-1){
>      JsMenuShow();
>}
> 
> if(document.URL.indexOf("link2_item.html")!=-1){
>      JsMenuShow();
>}
> 
> And the html page to display these items
> ------------------------------------------
> <script language="JavaScript" type="text/javascript"

language="JavaScript" is even more ancient.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

external javascript menu - highlight current page ba pal <bpascal362@gmail.com> - 2014-07-02 01:17 -0700
  Re: external javascript menu - highlight current page ba pal <bpascal362@gmail.com> - 2014-07-02 01:19 -0700
  Re: external javascript menu - highlight current page "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-07-02 11:48 +0200
  Re: external javascript menu - highlight current page Christoph Michael Becker <cmbecker69@arcor.de> - 2014-07-02 22:35 +0200

csiph-web