开发者

catch copy+paste event of locationbar URL (jquery)

开发者 https://www.devze.com 2023-01-04 18:01 出处:网络
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 l

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+pas开发者_JAVA百科ting 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. :)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消