How to store and retrieve the previous URL within the Cookie

Asked

Viewed 1,345 times

3

The whole script is in the bookmarks/bookmarks bar, named: Bookmarklet

I’ve already drawn up the script. Behold:

Before c/ referrer

javascript: var URL = document.referrer; location.href = URL;

Now c/ cookie

javascript: var URL = window.location; link = document.cookie; link = URL; location.href = link;

I’m afraid I can’t imitate method referrer with a cookie. That would be my interest.

Does anyone have an idea of how to reference a previous URL without using the method document.referrer?

  • Another possible way would be to store in cookies a reference to the previous link, when you want to just use it. So you can reduce the amount of GET traverse parameters

2 answers

3

If you want to redirect via "Favorites" use this:

// Pega o link atual
var link = window.location.href; 

// Redireciona para o site contendo o link
window.open("http://9xbuddy.com/download?url="+link);

Ending:

javascript: var link=window.location.href;window.open("http://9xbuddy.com/download?url="+link);

Do the same thing you asked, you will get the same result without any page or HTML being injected or created. ;)

Supposed to support Favicon by creating such elements:

$('head').html("<link rel='image_src' href='https://9xbuddy.com/img/9xbuddy.jpg'><script>window.open('http://9xbuddy.com/download?url='+window.location.href, '_self');</script>");

In this case it is necessary to load Jquery, so it will result in:

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="https://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){$('head').html("<link rel='image_src' href='https://9xbuddy.com/img/9xbuddy.jpg'><script>window.open('http://9xbuddy.com/download?url='+window.location.href, '_self');</script>");});
  • None of the three options presented Favion in the tested browser, but the last one mentioned here has a similar behavior, I do not know to what extent it is sufficient.
  • I tested add your code "as is" and does not present any favicon. I tried to elaborate something similar to what occurs by injecting a <script> and a <link>, using Jquery, but can only use pure Javascript, I quickly did in Jquery. I am currently editing.

  • Does this code you posted, which creates the element and redirects, display the favicon correctly or not even that? I used to think the problem was just redirecting, then I realized I needed to redirect and have a favicon. Now I just want to know if Favicon is even working. In tests neither Favicon was presented, with Jquery nor with what is in the post. I looked for some "more elaborate" examples, like this one: http://del.icio.us/tools. It also doesn’t show any favicon. I believe there is no way to get this. An alternative would be to create a browser extension/plugin.

2


You can use a Cookie to do this. Take into account that a Cookie it’s not safe.

To use a Cookie you should use in format chave=valor; because then you can gather several cookies and always know which is which.

So in this case, to write:

document.cookie = 'ultimoUrl=' + window.location.href;

To read, you need to take the value of the string document.cookie and you can do it like this:

function lerCookie(nome) {
    var regex = new RegExp('(?:(?:^|.*;\s*)' + nome + '\s*\=\s*([^;]*).*$)|^.*$');
    return document.cookie.replace(regex, "$1");
}

document.cookie = 'MeuCookie=SOpt;';
console.log(lerCookie('MeuCookie')); // 'SOpt'

jsFiddle: https://jsfiddle.net/dhmwsxuq/

  • Grateful for the feedback!

  • @diegofm Forgive me the ignorance but with me the error. Now I cleaned the history along with cookies and browser cache, and finally ended up rebooting the PC. And still not accessing jsFiddle, but in any case this all right I’m just updating my topic, as I usually get a little worried if others are also having the same problem.

  • @Diegohenrique strange, I’ll ask someone else to test.

  • @diegofm I found out why I couldn’t access the example of Sergio - jsFiddle. Whenever you visit a website, they start with "HTTP" or "HTTPS". Both are the same Hypertext Transfer Protocol, but with an extra "S" results in the word: Secure. But in my case I need to reiterate the "S" leaving it without only http://

Browser other questions tagged

You are not signed in. Login or sign up in order to post.