fragment-identifier

URL Fragment and 302 redirects

让人想犯罪 __ 提交于 2019-11-26 00:35:59
问题 It\'s well known that the URL fragment (the part after the # ) is not sent to the server. I do wonder though how fragments work when a server redirect (via HTTP status 302 and Location: header) is involved. My question is really two-fold: If the original URL had a fragment ( /original.php#foo ), and a redirect is made to /new.php , does the fragment part of the original URL simply get lost? Or does it sometimes get applied to the new URL? Will the new URL ever be /new.php#foo in this case?

Modifying location.hash without page scrolling

旧巷老猫 提交于 2019-11-26 00:32:08
问题 We\'ve got a few pages using ajax to load in content and there\'s a few occasions where we need to deep link into a page. Instead of having a link to \"Users\" and telling people to click \"settings\" it\'s helpful to be able to link people to user.aspx#settings To allow people to provide us with correct links to sections (for tech support, etc.) I\'ve got it set up to automatically modify the hash in the URL whenever a button is clicked. The only issue of course is that when this happens, it

On - window.location.hash - Change?

筅森魡賤 提交于 2019-11-25 23:57:24
问题 I am using Ajax and hash for navigation. Is there a way to check if the window.location.hash changed like this? http://example.com/blah #123 to http://example.com/blah #456 It works if I check it when the document loads. But if I have #hash based navigation it doesn\'t work when I press the back button on the browser (so I jump from blah#456 to blah#123). It shows inside the address box, but I can\'t catch it with JavaScript. 回答1: The only way to really do this (and is how the

How to remove the hash from window.location (URL) with JavaScript without page refresh?

南楼画角 提交于 2019-11-25 22:31:54
问题 I have URL like: http://example.com#something , how do I remove #something , without causing the page to refresh? I attempted the following solution: window.location.hash = \'\'; However, this doesn\'t remove the hash symbol # from the URL. 回答1: Initial question: window.location.href.substr(0, window.location.href.indexOf('#')) or window.location.href.split('#')[0] both will return the URL without the hash or anything after it. With regards to your edit: Any change to window.location will

How can you check for a #hash in a URL using JavaScript?

天涯浪子 提交于 2019-11-25 22:28:30
问题 I have some jQuery/JavaScript code that I want to run only when there is a hash ( # ) anchor link in a URL. How can you check for this character using JavaScript? I need a simple catch-all test that would detect URLs like these: example.com/page.html#anchor example.com/page.html#anotheranchor Basically something along the lines of: if (thereIsAHashInTheUrl) { do this; } else { do this; } If anyone could point me in the right direction, that would be much appreciated. 回答1: Simple: if(window

Should I make HTML Anchors with 'name' or 'id'?

故事扮演 提交于 2019-11-25 22:25:42
问题 When one wants to refer to some part of a webpage with the \" http://example.com/#foo \" method, should one use <h1><a name=\"foo\"/>Foo Title</h1> or <h1 id=\"foo\">Foo Title</h1> They both work, but are they equal, or do they have semantic differences? 回答1: According to the HTML 5 specification, 5.9.8 Navigating to a fragment identifier: For HTML documents (and the text/html MIME type), the following processing model must be followed to determine what the indicated part of the document is.

Change the URL in the browser without loading the new page using JavaScript

梦想的初衷 提交于 2019-11-25 22:04:16
问题 How would I have a JavaScript action that may have some effects on the current page but would also change the URL in the browser so if the user hits reload or bookmark the new URL is used? It would also be nice if the back button would reload the original URL. I am trying to record JavaScript state in the URL. 回答1: With HTML 5, use the history.pushState function. As an example: <script type="text/javascript"> var stateObj = { foo: "bar" }; function change_my_url() { history.pushState(stateObj

How to get Url Hash (#) from server side

萝らか妹 提交于 2019-11-25 21:55:33
问题 I know on client side (javascript) you can use windows.location.hash but could not find anyway to access from the server side. 回答1: We had a situation where we needed to persist the URL hash across ASP.Net post backs. As the browser does not send the hash to the server by default, the only way to do it is to use some Javascript: When the form submits, grab the hash ( window.location.hash ) and store it in a server-side hidden input field Put this in a DIV with an id of " urlhash " so we can

What&#39;s the shebang/hashbang (#!) in Facebook and new Twitter URLs for?

梦想的初衷 提交于 2019-11-25 21:43:20
问题 I\'ve just noticed that the long, convoluted Facebook URLs that we\'re used to now look like this: http://www.facebook.com/example.profile#!/pages/Another-Page/123456789012345 As far as I can recall, earlier this year it was just a normal URL-fragment-like string (starting with # ), without the exclamation mark. But now it\'s a shebang or hashbang ( #! ), which I\'ve previously only seen in shell scripts and Perl scripts. The new Twitter URLs now also feature the #! symbols. A Twitter profile

Detecting Back Button/Hash Change in URL

烈酒焚心 提交于 2019-11-25 20:55:27
I just set up my new homepage at http://ritter.vg . I'm using jQuery, but very minimally. It loads all the pages using AJAX - I have it set up to allow bookmarking by detecting the hash in the URL. //general functions function getUrl(u) { return u + '.html'; } function loadURL(u) { $.get(getUrl(u), function(r){ $('#main').html(r); } ); } //allows bookmarking var hash = new String(document.location).indexOf("#"); if(hash > 0) { page = new String(document.location).substring(hash + 1); if(page.length > 1) loadURL(page); else loadURL('news'); } else loadURL('news'); But I can't get the back and