Saving browser history using Javascript bookmark

I am working on a bookmarklet that offers links when you click on it. I think that after clicking one of these links, when someone clicks the "Back" button, we intend to return to the list of links that the bookmarklet offers.

However, I do not see the possibility of making this possible with the help of a bookmarklet that can be launched on any web page. When you click on the suggested link and then go back, the original page is brought up without any Javascript from the bookmarklet, which usually displays a list of links at the top of the page.

Of course, the user can simply click the bookmarklet again, but it would be nice if this were not required. Is there a way to do this without redirecting the website hosted by me (which is a terrible IMO solution)?

+3
source share
4 answers

How about a bookmarklet that contains some html in a row, and then uses a combination window.locationand document.write()to display it?

var links = "<html><head><title>Suggested links</title></head><body>";
links += "<p><a href='http://example.com/'>Example Suggested Link</a></p>";
links += "</body></html>";
window.location = 'javascript:document.write("' + links + '");' ;

You have to be careful with your quotation to make sure that the correct line is displayed, but after a quick test it seems that it supports the back button ...

: http://jsbin.com/ebuko4 - Firefox, ...

:

<html>
  <head>
    <title>JS Bin Sample bookmarklet</title>
  </head>
  <body>
    <p><a href='javascript:(function(){ var l = "<html><head><title>Does this bookmarklet work?</title></head><body><p>"+ "<a href=\"http://example.com/\">Suggested link: Example.com</a></p>" + "<p><a href=\"http://example.net/\">Suggested link: Example.net</a></p>" + "</bo" + "dy></html>"; window.location = "javascript:document.write(%27" + l + "%27);"; })()'>Sample Bookmarklet - drag me to your toolbar</a></p>
  </body>
</html>
+2

, , - - , javascript - , .

, . , , , . Mozilla/Firefox , javascript XUL ( Mozilla GUI) . : https://developer.mozilla.org/en/extensions

IE, . IE? .

: : , , iframe. iframe. , , (, , SO - iframe, target = "_ blank" ), .

+1

, . .

iframe. , , , .

, stackoverflow! grrr.

: http://hwi.ath.cx/joeys_bookmarklets.html#splitpreview

0

, (, #info =... URL- ), , , .

If the bookmarklet is on the toolbar, it will be a one-click operation. But this can cause a new problem: how to get fresh results when the bookmarklet tries to show the results on the previous page!

0
source

Source: https://habr.com/ru/post/1778485/


All Articles