sneeu
11-21-2008, 05:00 AM
Hi Guys when ever I visit my site on the net I type the address and when I use my javascript a # sign appears? www.creativelinkltd.co.uk :eek:
|
Click to See Complete Forum and Search --> : Why is there a # at the end of my url when visited in my browser? sneeu 11-21-2008, 05:00 AM Hi Guys when ever I visit my site on the net I type the address and when I use my javascript a # sign appears? www.creativelinkltd.co.uk :eek: KDLA 11-21-2008, 08:12 AM It means that your javascript probably has coding like this to initiate it: <a href="" onclick="whatever()">text</a> <a href="javascript:whatever();">Text to Click</a> sneeu 11-21-2008, 09:51 AM Thanks, is this a bad thing? KDLA 11-21-2008, 10:17 AM Not really. The other method is just more "standard." toicontien 11-21-2008, 11:00 AM This would actually be best: <a href="#" onclick="whatever(); return false;">text</a> The "return false" part prevents the link click from going through. The "#" is seen in the address bar because the links makes the browser go to that anchor. Some browsers, when they try to go to the "#" anchor instead of "#anchor_name", it jumps the browser to the top of the screen. If you don't want the browser to follow a link when the link has an onclick event handler, then you need to return false in the onclick. toicontien 11-21-2008, 11:10 AM As an aside, when you see this: <a href="javascript: foo()"> It's kind of non standard. The "javascript:" part of the URL is a protocol identifier, just like "http:". The href says "Use the JavaScript URL protocol to interpret the rest of the URL. Browsers just assume the rest of the URL is JavaScript code and passes that code through the JavaScript interpreter. I prefer to remove any mention of "javascript" from the user interface. When you hover over a link, you'll see the URL for that link in the status bar of the browser. The user then sees "javascript: geeky_code()". I sometimes put in a short, descriptive anchor name and save the JavaScript for the onclick event handler: <a href="#full_view" onclick="fullView(); return false;">Full view</a> That's, of course, only if you aren't opening a new window or showing a previously hidden box of content on the page. When opening a new window, you should make the pop up link accessible (http://www.alistapart.com/articles/popuplinks). When showing a previously hidden box of content on the page with the link, put the Id of the HTML tag that gets shown as the anchor name: <a href="#more_info" onclick="showMoreInfo(); return false;">More Info</a> <div id="more_info">blah blah blah</div> If JavaScript is disabled, the link will work normally, jumping the user down to the "more_info" block. JavaScript hides that "more_info" DIV, then shows it, thus making it accessible. And boy did I ramble on and on about this. :) felgall 11-21-2008, 05:19 PM Actually the following would be even better if you don't want the text to actually link to anywhere when JavaScript is disabled. <span onclick="fullView()">Full View</a> and even better than that would be to give the span an id and move the onclick out of the HTML into a separate JavaScript file where it belongs. toicontien 11-21-2008, 05:35 PM It's not keyboard accessible though. In reality, you'd want to use: <button type="button" onclick="fullView();">Full View</button> The "button" type BUTTON element was created specifically when you need a user interface element that does nothing unless you apply some scripting. But alas, if you want that button to look and function like a link when you hover over it, IE won't play ball. There are also some style quirks to BUTTON elements that make them ill suited when you want a link that does nothing but whatever JavaScript tells it too. For that, an <a> tag that cancels the onclick does best. sneeu 11-24-2008, 03:47 AM Thanks again guys. I will try make the site more standard. Cheers webdeveloper.com
Copyright WebMediaBrands Inc., All Rights Reserved. |