Hi,
I have a short question. I have set a link to a pdf file. I use not the feature “download pdf” …
I only set a link, for example: mysite.com/media/flyer.pdf
then I put the file on the server. It works. But sometimes there is for a few weeks no flyer.pdf with new sales or something. Is it possible to set the same link when the file is not found and then I get redirect on a page I have made with text…for example next flyer coming soon …
hard to explain
sorry
tom
Hi @tom2
It’s possible, but you will need to set up some js to check if the link exists, sim. to this:
The js:
function checkLocation (e, loc) {
e.preventDefault();
$.ajax({
type: ‘HEAD’,
url: ‘http://www.yoursite.com/page.html’
})
.done (function(loc) {
// page exists
window.location = loc;
})
.fail (function() {
// page does not exist
window.location = “http://www.yoursite.com/newpage.html”;
});
}
The html:
<a href="http://www.yoursite.com/page.html" onclick="checkLocation(e, 'http://www.yoursite.com/page.html')" >Click Here</a>
Not tested, but I think all these pieces should be right or very close anyway
Bill
BricsDesign
HI @Bill
thanks a lot for your help …I am soooo bad in coding
Do I need an editor to write a js file ?
Are this the steps:
- write the js file
- put the js file in the project ? ( but where ? )
- put the html code into the page settings ?
thanks Tom
Hi @tom2
Sorry for the delay, I don’t get email notices - bummer.
Yes, you need a simple text editor - I use BBEdit - free version
- Yes, copy my code into a file and name it something.js and put it w/ your other files for your site. Obviously you’ll need to edit the code to match what you need.
- Page > Settings & click plus button for header file attachments and browse to the file you created
- Put the html code in a Code Widget bric.
Have fun.
Bill
BricsDesign