Mobile Redirect with javascript - javascript

I have this redirect, and it works great. However, I want the user to be able to access the desktop site when they request it via a link on the external mobile site at m.flyeurova.com. How can I do this?
<script type="text/javascript">
var isMobile = function() {
//console.log("Navigator: " + navigator.userAgent);
return /(iphone|ipod|ipad|android|blackberry|windows ce|palm|symbian)/i.test(navigator.userAgent);
};
if(isMobile()) {
window.location.href = "http://m.flyeurova.com/";
}
</script>

Related

Authenticate on button click using jQuery

So I am stuck on a specific piece and I can't seem to figure it out, so what I'm attempting to do is that I have a button and when it's clicked, it will open the link in the window and the users will authenticate and then it will redirect back to the page with a code from Instagram.
What I'm attempting to do:
When someone clicks on the #insta-auth button, it will open the getAuthentication function link in the same tab.
So let's say that window.location.origin is https://test.com/, the Instagram URL will return it as https://test.com/?code=debsfbdfb.
For some reason, I attempted onclick="" and $().onClick and nothing has worked so far, all help would be appreciated!
The snippet shows the button.
// Setup out Instagram object
var FHInstagram = window.FHInstagram || {};
FHInstagram.name = "";
FHInstagram.version = "2.0.0";
(function ($, window, document, undefined) {
// Define our Instagram object
const Instagram = {
APP_ID: '32222516',
API_URL: 'https://graph.instagram.com/',
API_OAUTH: 'https://api.instagram.com/oauth/authorize',
API_OAUTH_TOKEN_URL: 'https://api.instagram.com/oauth/access_token',
API_FIELDS: 'caption,media_url,media_type,permalink,timestamp,username',
// Authenticate Instagram
getAuthentication: function () {
return "https://api.instagram.com/oauth/authorize?client_id=" + this.APP_ID + "&redirect_uri=" + window.location.origin + "&scope=user_profile,user_media&response_type=code";
},
};
})(jQuery, window, document);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="insta-authenticate">Authenticate Instagram</button>
$('#insta-authenticate').on('click', function() {
-- do your instagram stuff here, getAuthentication();
}

How to print in chrome on android using jquery since google cloud print is deprecated?

I want to print the page on load in both Windows and Andriod using any browser including google chrome.
I have tried to print on crome in Andriod phone using window.print() but it was giving error,
<script type="text/javascript">
setTimeout(function () {
if (typeof(window.print) != 'undefined') {
window.print();
window.close();
}
}, 1500);
</script>
So I tried some help from google cloud print and what I found is that, it's been deprecated since 31th Dec 2020.
Here is my code for that,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
setTimeout(function () {
if (isAndroid) {
// https://developers.google.com/cloud-print/docs/gadget
var gadget = new cloudprint.Gadget();
gadget.setPrintDocument("url", $('title').html(), window.location.href, "utf-8");
gadget.openPrintDialog();
} else {
if (typeof(window.print) != 'undefined') {
window.print();
window.close();
}
}
}, 1500);
</script>
Can anyone help me in this.
I want to print the URL on load in both Windows and in Andriod.
I implemented as follow:
Added iframe element to page
<iframe id="print-frame" class="print-frame" title="Print" src="https://www.w3schools.com" onload="print"></iframe>
print-frame {display: none}
function print() {
var frame = document.getElementById('print-frame');
if (!frame) return;
var frameWindow = frame.contentWindow;
if (!frameWindow) return;
frameWindow.print();
}
iframe is hidden but onload it opens print dialog. On windows it's enough for printing.
for android I use PaperCut https://www.papercut.com/products/free-software/mobility-print/
Install server part on PC where printers are connected, share printers in admin web UI.
On Android install MobilityPrint app, turn on Print service 'Mobility Print'
then in Chrome browser select Share->Print and select any MobilityPrint service printer

Detect OS and redirect to mobile app installed

I have attached below the mobile app button click, Its perfectly working for Android device, only getting an error: safari cannot open the page because the address is invalid, before being redirected to the redirect URL, can you please anyone help me to resolve the issue
<script type="text/javascript">
function myHref() {
if (navigator.userAgent.match(/iPad/i) || (navigator.userAgent.match(/iPhone/i))) {
document.location = 'app://url2';
setTimeout(function () {
if (confirm('You do not seem to have the app installed. Do you want to go download it now?')) {
location.href = "https://apps.apple.com/";
}
}, 300);
}
if (navigator.userAgent.match(/Android/i)) {
location.href = "https://play.google.com"
}
}
</script>
GET
Website: https://wmiserver.com/dosa-hut

JavaScript Redirect not working with ?fbclid=

the community!
I'm going through some issues. the redirection feature doesn't work well when I try to post the link on the Facebook platform. in general, the redirection only works outside facebook community. when I click on the shared link on Facebook automatically set this parameter at the end of URL ?fbclid=
example : https://myblog.blogspot.com/go/fb?fbclid=
but when I put the link directly on the browser works properly
here is my code
<script language='javascript'>
//<![CDATA[
var key = window.location.href.split("go/")[1].replace("/","")
var urls={
'fb':'https://www.facebook.com',
}
if(key){
if(urls[key]){
window.location.href=urls[key]
}else{
document.write("'"+key+"' not found 😞");
}
}
//]]>
</script>
Use window.location.pathname instead of window.location.href.
<script>
//<![CDATA[
var key = window.location.pathname.split("go/")[1].replace("/","")
var urls={
'fb':'https://www.facebook.com',
}
if(key){
if(urls[key]){
window.location.href=urls[key]
} else {
document.write("'"+key+"' not found 😞");
}
}
//]]>
</script>

How to open an app without redirecting the page

I currently have a button. When it's clicked I execute a javascript code.
var openAppBtn = document.getElementById("openAppBtn");
openAppBtn.onclick = function () {
var app = {
launchApp: function () {
window.location.replace("testappscheme://")
}
};
app.launchApp();
};
<a id="openAppBtn" class="btn" href="">Open KWCP App</a>
when I execute this bit of code on iOS, the page does a refresh if the app is not installed. May I ask how do I attempt to open the app without the page redirecting.
You could use an iframe to trigger the app intent. Example code for triggering the intent on the page-load for example. Just put it inside your click function.
<script type="text/javascript" charset="utf-8">
var frame = document.createElement('iframe');
frame.src = 'testappscheme:/' + window.location.pathname + window.location.search;
frame.style.display = 'none';
document.body.appendChild(frame);
// the following is optional, just to avoid an unnecessary iframe on the page
setTimeout(function() { document.body.removeChild(frame); }, 4);
</script>
Simply by clicking the button, add an iframe to your page with the schema-url.

Categories

Resources