11

I have this javascript bookmarklet This appends the prompted value to www.oracle.com and opens that url in tab.

javascript:window.location.href='http://www.oracle.com/'+prompt("Please enter your input:", "exadata");

In firefox, this works fine. If I have some open tab with some website, clicking on this bookmark, open the expected site. oracle.com appended with value filled. This also works when I am in new tab and opens oracle url as expected.

But in chrome, this works fine if I have some site loaded in tab and click on this bookmark. But if I am in new tab page, clicking on this bookmark does nothing. It does not even show prompt box.

What I am missing here? Is it something related to how new tab page is handled in firefox and chrome?

2
  • Not sure what the issue is with your bookmarklet, but there is a better way to do this than a bookmarklet. Create a custom search engine. Type: chrome://settings/searchEngines into the address bar. Hit "add" Button. In form add Oracle next field add or and last field enter 'http://www.oracle.com/%s Click on save button. Now in the address bar type or hit space and now type your string you want like in the prompt. Jun 27, 2019 at 15:11
  • @epascarello yes that could be another solution, but I was wondering why javascript is not working on new tab page Jun 27, 2019 at 15:35

1 Answer 1

22

This seems due to some issue with disabling of javascript on new tab page due to security reasons.

More details can be seen here : https://bugs.chromium.org/p/chromium/issues/detail?id=98871#c2

From comments on above issue, I found same can be achieved as below if we treat it as data url (https://bugs.chromium.org/p/chromium/issues/detail?id=98871#c7) :

data:text/html,<script>window.location.href='http://www.oracle.com/'+prompt("Please enter your input:", "exadata");</script>

Hope it helps.

2
  • 1
    A JavaScript engine does appear to be available in the "New tab" window- when you open Chrome Dev tools and go to 'console', entering "window.open('example.com')" does work. But javascript: as a scheme won't access the engine, due to the restrictions cited above. Sep 28, 2021 at 15:36
  • This does work in Chromium, but does not work in Vivaldi. It opens some strange encoded symbols instead. Vivaldi version 6.1.3035.204. I filed bug report VB-99070
    – Ashark
    Jul 29 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.