Change all links from HTTP to HTTPS using Javascript Print

  • 2

Problem:
Links that use HTTP:// instead of HTTPS:// give certificate warnings on some browsers alerting that some content is not encrypted.
Normally, if you have access to the source code you can edit your links by deleting the http: part and just leaving the URLs begin with //
But I recently had this problem with a piece of code on one of my scripts that was encrypted with ioncube, so I could not edit the link directly on the source code.

Solution:
I was able to come up with this solution. It fixes all links on the client side by using Javascript/jQuery.

Put this code before the </head> tag:

<script src="//code.jquery.com/jquery-latest.min.js" >
</script>

<script type="text/javaScript"> $(document).ready(function() { $("a").each(function() { var i = $(this).attr("href"); var n = i.replace("http://", "https://"); $(this).attr("href", function() { return n; }) }) }); </script>

Was this answer helpful?

« Back