I need to make a link to open a page and add some scripts into it.
That's why i thought creating bookmarklet is the best way. For example, i want to redirect user to a page and alert user when he/she tries to close the tab.
The code i want to use
javascript:(function(){
window.location.replace("https://google.com");
window.onbeforeunload = function (e) {
e = e || window.event;
// For IE and Firefox prior to version 4
if (e) {
e.returnValue = 'Sure?';
}
// For Safari
return 'Sure?';
};
})();
I created anchor like:
<a href="javascript:(function(){window.location.replace("https://google.com"),window.onbeforeunload=function(e){return(e=e||window.event)&&(e.returnValue="Sure?"),"Sure?"};})();">Click</a>
Is it possible to do that? And what is wrong with the js code cause it doesnt works ?