I would like to know how to open up a url link from my website in the facebook and twitter app only if it is installed on the device, if not I would like the page to be open
You can try redirecting the phone to opening the app, and if nothing happens, redirect it to the web page you want.
setTimeout(function () { window.location = "https://itunes.apple.com/appdir"; }, 25);
window.location = "appname://";
If the second line of code works, then the first won't be executed.