I am using a small bookmarklet which opens a webpage in a new window. It works properly on chrome.
However, when I use the same in Firefox it opens a new window with new web page but the page on which this bookmarklet was clicked is forwarded to some page with text [object Window]
. How do I solve this issue?
My code:
<a href="javascript:open('http://www.google.com','targetname','height=500,width=500');">Bookmarklet</a>
Please let me know how to solve this issue.
Thanks
Bookmarklets are browser bookmarks that execute JavaScript instead of opening a webpage. They're also known as bookmark applets, favlets, or JavaScript bookmarks. Bookmarklets are natively available in all major browsers, including Mozilla Firefox and Chromium-based browsers like Chrome or Brave.
Just click the bookmarklet and your browser will run it on the current page. If you don't have a bookmarks toolbar — such as on Safari on an iPad or another mobile browser — just open your browser's bookmarks pane and tap or click the bookmark.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With