tags:

views:

28

answers:

1

I'd like to catch the event of a user copying the link from the browser's location-bar.

The user is browsing through my site, finds a page that she likes, selects the URL currently on her browser location bar (window.locationbar focus) and copys the URL to paste it elsewhere (facebook, ...). I would need to catch this event and change the text the browser copys to the clipboard.

Why? my website is AJAX driven, it relies heavly on the location.hash manipulation to navigate around. it uses the '#!' syntax employed by googlebot (source).

So, if a user is here: mysite.com/#!cool-page and wants to share this link by copy+pasting it from the locationbar, I'd like her to have mysite.com/?_escaped_fragment_=cool-page as the text to share around. It's not URL cloaking ;)

A jquery hack or any other idea would be appreciated. :)

+3  A: 

There is no way using ecmascript / javascript to catch a keypress, keydown or keyup event if the browsers navigationbar is focused.

So you need to create a custom functionality, like a button or shortcut, which copys the current URI into the clipboard. See http://stackoverflow.com/questions/400212/how-to-copy-to-clipboard-in-javascript for a further read.

jAndy
yes, I was "feeling" it coming that way, not being possible. thanks for the link. ;)
sopppas