Can someone help me with url hash? I use this code to get the current url and then send the data as json, but the hash part seems to be stripped then. i tryed to use href and hash and i always get the default.aspx but no hash part like #anchor.
var location = String(window.location);
var title = String(document.title);
var text = { 'url': location, 'title': title };
Thanks for help guys. I figured it out. All answers were correct as well as my code. I just put it in wrong event hadler. Because my hash parts are generating dynamically. Sor开发者_运维问答ry for disturbing you guys!!!
Try looking at the window.location
object. It has these properties:
assign: function () { [native code] }
hash: "#test"
host: "stackoverflow.com"
hostname: "stackoverflow.com"
href: "getting parts of url window.location"
pathname: "/questions/2538697/getting-parts-of-url-window-location"
port: ""
protocol: "http:"
reload: function () { [native code] }
replace: function () { [native code] }
search: ""
I think you must be doing something wrong. You're not showing us all the code involved. Here is a test page: http://gutfullofbeer.net/location.html#something
When you click that link, what do you see?
Have you tried using window.location.href
instead of window.location
?
window.location
is an object, window.location.href
is a string.
I'm not sure by the comment in your question, but did you try window.location.hash
?
精彩评论