简体   繁体   中英

How can I open URLs in a new tab across all browsers with a bookmarklet?

I writing bookmarklet to open all twitter img in newtab but it not give same result with difference browser

This is result I try

firefox 64.0.2 work on normal and private but it change original url to my bookmarklet script

firefox 64.0.2 portable not working both

chrome 71.0.3578.98 only 1 image on normal ,incognito not working

vivaldi 2.2.1388.37 work on normal perfectly ,private not working

Ex. twitter link https://twitter.com/RadioPakistan/status/1084765300183179264

EDIT: I make it to use but...

firefox sitll open newtab and replace original tab url to bookmarklet script url

Edit2: I just add history.go(-1) after loop for prevent firefox redirect web url to script url

javascript:$=jQuery;$(".twOpenOriginalImage_touched").each(function(){var url=$(this).attr("src");window.open(url,"_blank");});

working bookmarklet

javascript:$=jQuery;$("img[data-aria-label-part]").each(function(){var url=$(this).attr("src");window.open(url,"_blank");});

C&P I have done some searching but have found very little documentation on what can be done in a bookmarklet which cannot be done in a normal web page

That is because there is essentially none. For all practical purposes, running a bookmarklet is exactly the same as running script on the page. It is almost precisely equivalent to clicking a link on the page that has href="javascript:.."

although having written some bookmarklets already it seems they have a bit more privileged status than a normal web page (although this seems to vary by browser).

I've have also written and researched a lot about bookmarklets (check my SO history). I have found only 2 significant differences.

1.) You can use %s in the bookmark's URL in combination with a bookmark keyword for argument substitution via the URL bar.

2.) There is a weird hack in Chrome (which could easily get closed with some future update) which lets a bookmarklet open a URL in a new tab and then run code in that tab if and only if the user does CTRL+click on the bookmarklet. But that still doesn't let you do anything to tabs which are already open.

If you know others, let me know.

The only solution is to create a browser extension. If you can write a bookmarklet, it isn't much more complicated to write a very basic extension.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM