Search code examples
javascriptbookmarklet

Opening a new tab with clipboard contents as a variable?


I will have a geographic coordinates in my clipboard and wish to open a google maps link with those coordinates. I am trying to create either a bookmarklet or a script that is triggered by a keyboard shortcut.

I was trying to turn this into a bookmarklet but was not sure where I was messing up.

coords = window.clipboardData.getData('Text')
window.open('https://google.com/maps/search/${coords}', '_blank');

Solution

    • This can be done using navigator
        navigator.clipboard.readText().then(
            clipText => window.open(
                'https://google.com/maps/search/'+clipText, '_blank'
            )
        );