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?

Kuldeep Singh
  • 1,214
  • 4
  • 18
  • 45
  • 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. – epascarello Jun 27 '19 at 15:11
  • @epascarello yes that could be another solution, but I was wondering why javascript is not working on new tab page – Kuldeep Singh Jun 27 '19 at 15:35

1 Answers1

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.

Kuldeep Singh
  • 1,214
  • 4
  • 18
  • 45
  • 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('http://example.com')" does work. But javascript: as a scheme won't access the engine, due to the restrictions cited above. – blackcatweb Sep 28 '21 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 '23 at 10:06