MrFish Posted October 12, 2009 Share Posted October 12, 2009 I like to include ajax in my site whenever possible. This has its benefits but I've realized a major problem it causes. If you include a variety of pages into one page, you disable the back button and the back button is one of the most used features of the browser. I've seen some sites using the pound symbol (#) to automatically move to anchor points, can it be used for javascript and php? Link to comment Share on other sites More sharing options...
chibineku Posted October 12, 2009 Share Posted October 12, 2009 The # symbol is used in links to refer to an element with a specific id. For example:<a href="#main">main</a>Will take you to,<div id="main"> ... </div>I don't know about implementing it with plain JavaScript or PHP, but you can easily use jQuery to import only specific elements by referencing their ids (or classes, actually). For example, to load the main div from one page and import it into the main div in the current page when you click on a button, you could do: $(document).ready(function() {$('#id_of_button').click(function() {$('#main_div_of_local_document').load('filename.html #main_div_of_remove_document');return false; //this line only if you use an anchor to start things off, to stop the link going anywhere});}); The thing about this is it will end up with two divs with id 'main'. You would probably change the selector for the load function to #main #content, or some other wrapper for the content in the main id. Link to comment Share on other sites More sharing options...
Synook Posted October 12, 2009 Share Posted October 12, 2009 You can access and set the hash part of the URL through the window.location.hash property. Link to comment Share on other sites More sharing options...
MrFish Posted October 13, 2009 Author Share Posted October 13, 2009 chibineku:Yes but that is irrelevant to the pound symbol in a url. At least I believe so.Synook:Ok, thanks. I'll look into it. Link to comment Share on other sites More sharing options...
Synook Posted October 13, 2009 Share Posted October 13, 2009 Note - in this case it is the "hash" symbol, and yes, going to page#someid will cause the browser to scroll to the element with id="someid" (however changing it after the page loads won't cause a jump). By the way, you can also artificially insert entries into the browser's history. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.