0

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. :)

Trident Splash
  • 649
  • 2
  • 10
  • 25
  • 1
    @soppas: I think most sites have a "share this link" input field when they want to track link sharing. Also, you can discover your popular pages through a variety of web site traffic (or log file) analysis programs. (Aside: I don't think it's possible to capture mouse clicks that are outside of the browser's main canvas area using JavaScript.) – Dave Jarvis Jun 27 '10 at 20:31
  • yes, indeed... but let's face it, a vast majority of webusers prefers to copy+paste the link on the locationbar, then use any of the buttons we may have on the document to share content... just look at the user experience with youtube, I bet people don't use their share buttons, but rather copy+paste it from the locationbar. – Trident Splash Jun 27 '10 at 20:44

1 Answers1

3

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 How do I copy to the clipboard in JavaScript? for a further read.

Community
  • 1
  • 1
jAndy
  • 231,737
  • 57
  • 305
  • 359