Bookmarklet to open a new window forwards current window to [Object Window]? Bookmarklet to open a new window forwards current window to [Object Window]? google-chrome google-chrome

Bookmarklet to open a new window forwards current window to [Object Window]?


You have to "eat" last return value in the JavaScript URL, returning anything typeof returnValue != 'undefined' will be equivalent to invoking document.write(returnValue). And window.open returns newly created window object, hence the output of "[object Window]". Surely, you can do that by mindlessly appending void(0) statement, but it is SO clumsy. No-magic version (return value eaten, calling window left undisturbed):

javascript:void(open('http://www.google.com','targetname','height=500,width=500'))

You are likely will expand your bookmarklet, so to prevent cluttering global scope, you'd better go anonymous function way (note the absence of return statement):

javascript:(function(){open('http://www.google.com','targetname','height=500,width=500');/* more code to go */})()


Try this code, I have added "void(0);" to stop the parent window go away after clicked.

<a href="javascript:open('http://www.google.com','targetname','height=500,width=500');void(0);" >Bookmarklet </a>