简体   繁体   中英

Creating simple bookmarklet in javascript

I'm trying to pick up the selected text of a document in a bookmarklet. How do I implement this?

I got this from the internet. Why does this not work?

javascript: Q=document.selection?document.selection.createRange().text:document.getSelection(); alert(Q);

Thanks!

You have to select text first. It alerts selected text in the page. If you just put that code in your address bar in alerts null because no text is selected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM