Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript graceful degradation

HEllo,

Does this look ok:

<a href="directlinktopurchasepage" target="_blank" onclick="return loadBuyPopup()">Buy Now</a>

function loadBuyPopup() {
 //do something
 return false;
}

Ideally I want the popup to load, but just incase the JS fails (i.e. it may load slowly and the user is in a hurry), then it should still allow the user to purchase using an ugly page.

Will this work in all browsers or am I missing something?

like image 323
Alec Smart Avatar asked Feb 24 '23 03:02

Alec Smart


1 Answers

Yes you are right. If the browser does not support JS, then the normal link (also the href) is going to be used for the link. Otherwise the onclick JS function will be called.

like image 87
Nicolas Avatar answered Feb 26 '23 21:02

Nicolas