Question

This is what I need to accomplish. Say I go to example.com on Chrome browser. I have a certain bookmark on my browser, on which when I click it automatically takes the example.com URL and adds a certain string, for example cache: and when I click that bookmark it will take me to cache:example.com When I go to example2.com and click on the bookmark again, it will take me to cache:example2.com Is there a Javascript code or else that can make this possible?

Was it helpful?

Solution

Just add some javascript to change the window.location.href attribute.

The following will help

javascript:(
    function(){
        f='cache:'+window.location.href;
        if(!window.open(f))
            location.href=f;
    }
)()

You can change and set the href to whatever you want

You have to add this javascript to an anchor tag so that when the link is dragged and dropped in a browser's bookmarklet bar, it get added. So the link will be like this:

<a title="GotoCache" href="javascript:(function(){f='cache:'+window.location.href;if(!window.open(f))location.href=f;})()">Goto Cache</a>

Add this link in a page and you are set :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top