Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript bookmarklet does not work in new tab in chrome

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?

like image 375
Kuldeep Singh Avatar asked Jun 27 '19 15:06

Kuldeep Singh


1 Answers

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.

like image 58
Kuldeep Singh Avatar answered Oct 05 '22 04:10

Kuldeep Singh