1

I have an existing script (in a bookmarklet) that only works with the http:// version of the page. When I am on the https:// version of the page, I want to load the http:// version using:

add = window.location.href;
if(add.indexOf('https') == 0){
  window.location.href = 'http' + add.slice(5);
}

and then allow the bookmarklet to run on the new page. Is there a way to do this ?

Right now, I added the code above to the bookmarklet, and click it twice: the first click loads the http:// version of the page and the second click runs the original bookmarklet.

Thanks !!

Danny Delott
  • 6,756
  • 3
  • 33
  • 57
Suresh
  • 23
  • 4
  • 2
    That is considered cross site scripting, which browsers really try to block due to security issues. – Norbert Jun 17 '15 at 00:14
  • Thanks for the note ! I just read up on cross-site scripting, and I do not understand the similarity. – Suresh Jun 17 '15 at 00:26
  • It's because you have a script trying to redirect to a less secure version. The browser can interpret that as an attempt to clickjack. Additionally, if your script only runs on the http version of your page, I'd be curious why; it's possible there's security issues there too. SSL is one of the simplest things you can do to add a LOT of security. – Brian Jun 17 '15 at 00:27
  • OK. The redirection works fine and as expected, though, so I am still confused. But it is not so important that I understand :) So if I get this correctly, what I want to do is not trivially possible ? (The bookmarklet in question is the CiteULike bookmarklet, just btw. I do not know why it does not work with https://). – Suresh Jun 17 '15 at 00:32
  • @Suresh the short answer is: it is not trivial and it is VERY important to understand because you'll come across it often when you're trying to get information from one server to another server. The basics is that browsers try and stop people from calling other servers to run scripts/content from other sources because it could be malicious. it's a user thing – Daemedeor Jun 17 '15 at 00:47
  • Thanks ! I also found this: http://stackoverflow.com/questions/3256525/load-a-page-and-apply-javascript-in-a-single-bookmark?rq=1 which seems to indicate that Greasemonkey might help. – Suresh Jun 17 '15 at 01:56
  • In short don't do this. Don't try to hack it. The reason the bookmarklet is not working in https is the real problem that needs to be addressed. – ryandlf Jun 17 '15 at 02:28

0 Answers0