Ruben Bolink Ruben Bolink - 10 months ago 48
Javascript Question

How to rewrite part of a URL?

I'm using lightbox2 on my site and I want my viewers to download the image. The button works, it links to /view/directory/image.jpg and the download button shows just the image. In PHP I made a scripts that downloads the image and sets download+1 in mysql, the only thing i'm not so good at is JS.

Current JS code in lightbox2 is :

this.$lightbox.find('.lb-download').on('click', function (e) {

Which links to /view/directory/image.jpg because of the href whitch shows the image.
I want the lb-download button to go to /download/directory/image.jpg, I already got the download working, just not the and preg_replace part in JS.

** Maybe its just easier if I give you the site which its on, its

Both options didn't work so far


You can replace the part in the url with word view to download like this:

this.$lightbox.find(".lb-download").on("click", function (e) {"/view/", "/download/"))