Technical Discussion
  >> Web Design / HTML / Web hosting Forum


Register (or login) on our website and you will not see this ad.


These posts have been archived and can no longer be replied to or modified.
  Print Thread
Standard User cheshire_man
(member) Sat 26-Sep-09 21:44:30
Print Post

A javascript question


[link to this post]
 
Hope this is the right place to post this.

I do the web sites for our local church. They're pretty simple and straightforward. As a result of us having a new vicar who wishes to change the design I'm doing some work behind the scenes at the moment.

I try to use the correct syntax and keep to standards. So for example, I use & in HTML, etc. rather than &. I have what is really a very small but niggling problem in this regard.

In a javascript menu routine I have as a parameter string
{U:'index.php?view=parents_toddlers&ch=sp',T:'Parent&Toddlers'}
to call a particular page. However this doesn't work as it generates a URL
allhallows-church.org.uk/index.php?view=parents_toddlers&ch=sp
and thus gets the wrong page. If I change the parameter string to
{U:'index.php?view=parents_toddlers&ch=sp',T:'Parent&Toddlers'}
it generates a URL of
allhallows-church.org.uk/index.php?view=parents_toddlers&ch=sp
In other words the & in the 1st parameter is not being converted to &, but the & in the 2nd parameter is being so converted.

Any thoughts why?

[I've left the http:// off the front of the URLs to avoid them being treated as URLs]

Tony
Standard User deleted
(deleted) Sat 26-Sep-09 22:51:50
Print Post

Re: A javascript question


[re: cheshire_man] [link to this post]
 
According to a post here, in particular this post:
There is confusion here.

Encoding of special character depends on context. For instance, & must be encoded in HTML but not javascript, however, \ must be escaped in javascript but not in HTML.

Character entitites should not be used in javascript to create urls. You may use %nn to encode characters, however, at no point are these decoded automatically. If data is passed to a static html page using ?param1=%20&param2=%2A you will need to decode the query part of the url using the javascript function unescape.


I read that as it is fine to use the & instead of & in javascript smile
Standard User cheshire_man
(member) Sat 26-Sep-09 22:56:58
Print Post

Re: A javascript question


[re: deleted] [link to this post]
 
Thanks for that. Looking at the immediately following post in that board
As Kaled points out, we have two different contexts here. Within the context of a JavaScript href, the & is just fine and should not be encoded. In an HTML link the & is forbidden and should be escaped. In the HTML link context an HTML character entity will be decoded before the address is passed to the HTTP process; a URL-encoded character will not, as the server can read it directly.

In other words, in your example, the & should be escaped as & only within an HTML link, but left as & within a JavaScript location.href call.
confirms what you said - I think smile

Tony


Register (or login) on our website and you will not see this ad.

Standard User Ansolan
(newbie) Wed 30-Sep-09 22:56:35
Print Post

Re: A javascript question


[re: cheshire_man] [link to this post]
 
As a secondary point, are you sure you want to be using javascript in navigation anyway. Can be a problem for search engines and some visitors, not least those most likely to have accessibility issues in the first place.
Standard User cheshire_man
(member) Thu 01-Oct-09 22:51:27
Print Post

Re: A javascript question


[re: Ansolan] [link to this post]
 
An interesting point. Being very much a tyro in this area, do you have some suitable alternative suggestions?

Tony
Standard User Kenneth
(legend) Fri 02-Oct-09 08:04:03
Print Post

Re: A javascript question


[re: cheshire_man] [link to this post]
 
Are you using JavaScript to give you a menu style navigation - if so I'd use something like CSS menus - though sometimes easy to use JavaScript to do the hiding/pop-up.

If you are using JavaScript to create dynamic or changeable menus - then I'd consider doing it in a back end scripting language like php

Ken

Only two things are infinite, the universe and human stupidity, and I'm not sure about the former.
Albert Einstein (1879 - 1955)
Standard User cheshire_man
(member) Fri 02-Oct-09 08:38:15
Print Post

Re: A javascript question


[re: Kenneth] [link to this post]
 
It's purely drop down menus across the top of the screen our vicar wants. The menus are not changeable, I'd use php for that if necessary, I'm using it for other things anyway.

I'll look at CSS Menumaker - especially as it appears to be free smile Our current site uses CSS Menus anyway, that's raised a thought as to whether that basic code/technique is adaptable to horizontal menus - got it from www.dynamicdrive.com

Tony
Standard User deleted
(deleted) Fri 02-Oct-09 09:30:31
Print Post

Re: A javascript question


[re: cheshire_man] [link to this post]
 
I've got a css drop down menu on a website I was working on, I can send you the code later on if you like...
Standard User cheshire_man
(member) Fri 02-Oct-09 14:33:08
Print Post

Re: A javascript question


[re: deleted] [link to this post]
 
Yes please, that'd be most kind.

Tony
Standard User deleted
(deleted) Sat 03-Oct-09 21:33:26
Print Post

Re: A javascript question


[re: cheshire_man] [link to this post]
 
You have a PM smile
  Print Thread

Jump to