Jump to content

Detecting within-page links using js

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
CygnetGames

CygnetGames

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
This may seem a mad question but there is a genuine reason for it!

If someone visits my page: http://my-domain.com/my-page/
And then they change the url to: http://my-domain.com...page/#something (note the # symbol!)
Is there a way to detect this change using javascript?

They haven't clicked on a link to make this change (otherwise you could just use the onClick event of the link) they have typed into the address bar.

#2
TcM

TcM

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 11,147 posts
Well what do you want to do with that? Can you explain what would be the use of that? And I think that would be possible by breaking the URL using JS may be possible

#3
CygnetGames

CygnetGames

    Programmer

  • Members
  • PipPipPipPip
  • 119 posts
The application is an ajax search page.
The main point i'm trying to prove with this page is that ajax doesn't have to break the usability of a website. I want the user to be able to bookmark the page, use the forward and back buttons and send the url to a friend in ways that are familiar to them.

My first thought was to store the search criteria in the query string, but this breaks the ajax because changing the query string reloads the whole page from the server.

So my second thought was to make a fake "query string" after the # symbol (what's this part of the url called anyway?) like so:
http://my-domain.com...search_criteria
Because you can change this part of the url with javascript without the page being reloaded from the server.

This partly fulfils the requirements - the user can bookmark the page and send the url to a friend, and it will work as they expect.
But they can't use the forward or back buttons, or alter the url manually in the address bar.
So I need a way to detect, using javascript, when this portion of the url changes. I figured it must be possible, as the browser does something when it changes - normally it scrolls to the relevant section of the page.

And yes, I can break the url up using javascript - I need to do this when the page loads to parse the fake "query string".