Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

How to redirect to new page after download file has initiated? WordPress

  • SOLVED

Hi,
I run a site which gives away psd graphics as freebies. After the visitor has clicked the download link I want the page to redirect to a "thank you for downloading" page.

I now this is not a straight up WordPress inquiry but still, can anyone help me with this?

Orman over at Premiumpixels.com uses a method that seems cool.

Answers (7)

2011-11-28

John Cotton answers:

PremiumPixels is using this javascript to do it:


jQuery(function () {

// get the GET variables
var theme = getUrlVars();

var downloadLink = 'http://cdn.premiumpixels.com/uploads/' + theme['file'] + '.zip';

if(theme['file'])
{
jQuery('#downloadLink').attr('href', downloadLink);

delayedDownload();
}

function delayedDownload()
{
timeoutID = window.setTimeout(downloadTheme, 1000);
}

function downloadTheme()
{
window.location.replace(downloadLink);
//window.open(downloadLink,'','menubar=1,location=1,toolbar=1,width=600,height=500');
}

// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');

for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}

return vars;
}

});


So his link to the file is actually a link to another page with a query string variable (in this case, the name of the download file without .zip on it.

ie http://www.premiumpixels.com/download/?file=menu

What you are seeing is the contents of /download - try without the ?file=menu on the end....!

So the user clicks through to the next page (which could be anything of course - you could easily have some logic in there that detected the actual file being downloaded and change the contents of the page based on that) and then the script above fires off, reads the query string and downloads the file!


LeTune comments:

Hi John, could you help me implement this?

Send an email to [email protected]

2011-11-28

Gabriel Reguly answers:

Hi LeTune,

Use a meta tag.

<meta http-equiv="refresh" content="5; url=http://example.com/">

http://en.wikipedia.org/wiki/Meta_refresh


Regards
Gabriel

-- Edit: John Cotton gave a good answer, here is the link to the jQuery code [[LINK href="http://turbo.premiumpixels.com/wp-content/themes/premium/js/jquery.download.js?ver=3.2.1"]]http://turbo.premiumpixels.com/wp-content/themes/premium/js/jquery.download.js?ver=3.2.1[[/LINK]]

Maybe this code is not GPL, you should check it before using the code.

2011-11-28

Ali Hussain answers:

Do you use any plugin or is it that you place a download link directly?

2011-11-28

Julio Potier answers:

Hello

What kind of code are you using for the download link ?
Ajax mode ? or "just" click-to-get mode ?

See you soon

2011-11-28

Ryan Riatno answers:

You can use plugin to do that here's some:
http://wordpress.org/extend/plugins/download-monitor/
http://wordpress.org/extend/plugins/wp-downloadmanager/

There's option to redirect to a new page after user click download

2011-11-28

Hai Bui answers:

Premiumpixels.com use javascript/jQuery to do it. I can create the same function for you, but it only works if you insert the download links manually. PM me if you are interested.


LeTune comments:

Hi Hai,
I add download links via custom field, manually for every post. Send me an email at [email protected]

2011-11-28

Arnav Joy answers:

Try to run the code of downloading in the thanks page itself.
I have done it something similar in http://www.webgranth.com/ebook-tutorial
if it is uerfull to you then you can contact me at
[email protected]