How To Redirect To my Mobile Website - jquery-mobile

I am trying to redirect to my mobile website. This is the code I a am using in the head code of my homepage (index.html). This supposed to automatically redirect mobile devices to my mobile website, but it doesn't work.
<script>
if (document.location.search.indexOf("skipmobile") >= 0) {
document.cookie = "skipmobile=1";
}
else if ((document.location.hostname.match(/\.mobi$/) || screen.width < 699)
&& document.cookie.indexOf("skipmobile") == -1)
{
document.location = "mobile/";
}
</script>
Can somebody please give me some ideas about possible mistakes or improvements?
This is my website: www.accurateprinting.com

Related

SignalR usage and potential issues of getting connectionID in the masterpage

Recently, we have introduced SignalR into our project and hoping use its features. Currently SignalR is used only for showing progress bar on a couple of webpages on the client side for long running processes on the server. Could anyone help me with implementation of the SignalR and its ramifications?
.Net Framework Standard MVC application at at a time more than 3000 users connected to the webapp in Microsoft Azure hosted site.
SignalR is loaded and a connectionID is ($.connection.hub.start().done(function ().....) acquired in the _Layout.chtml. This is because, if the user may open different features in the webapp on different tabs and the these tabs may happen to have progress bars in it. So a unique connection ID on each Tab opened will help the SignalR to process the response.
I suspect a potential problem here for the page load performance and other unknown issues can be triggered because the layout page is opening a new connectionID each time the pages are loaded or refreshed.
Any other standard solution welcome if this is problematic.
Thanks for your help.
_Layout.chtml
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/ProgressBarHelper.js" type="text/javascript"></script>
<script src="~/Scripts/jquery.signalR-2.4.2.min.js" type="text/javascript"></script>
<script src="/signalr/hubs"></script>
<script type="text/javascript">
var connectionId = null;
$(function () {
// Reference the auto-generated proxy for the hub.
var progress = $.connection.progressHub;
//console.log(progress);
// Create a function that the hub can call back to display messages.
progress.client.AddProgress = function (message, percentage, reportmsg, showProgressReport, autoClose) {
if (CommonProgressBar.IsVisible() == false)
popupProgressBar.Show();
CommonProgressBar.SetPosition(percentage);
$('#popupProgressMessageText').text(message); //+ 'for ' + connectionId);
if (percentage == "100") {
if (autoClose == true) {
popupProgressReportText.SetText("Report");
popupProgressBar.Hide();
}
else {
popupProgressCloseButton.SetEnabled(true);
}
}
else {
if (autoClose == true) {
popupProgressCloseButton.SetEnabled(false);
}
}
var rptmsg = popupProgressReportText.GetText(); // $('#popupProgressReportText').GetText();
if (reportmsg != null && reportmsg != "") {
if (rptmsg != null && rptmsg != "") {
popupProgressReportText.SetText(rptmsg + "\r\n" + reportmsg);
}
else {
popupProgressReportText.SetText(rptmsg);
}
}
};
$.connection.hub.start().done(function () {
connectionId = $.connection.hub.id;
console.log(connectionId);
});
});
</script>

facebook redirect url not redirecting to intended url from facebook app

I have FB.init function to share on facebook. I am able to redirect to given redirect url through other browsers. But the same thing is not working on facebook app. It redirects me to the home url.
My function is defined as,
FB.ui({
method: 'share',
display: 'iframe',
href: "http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id,
picture: imageurl,
description: blog_description,
title: blog_title
},
function(response) {
console.log(response);
if (response && !response.error_message) {
console.log(response.status);
window.location = '/congrats'
}
else if (response && !response.error_message == "User canceled the Dialog flow") {
self.location.href = '/congrats'
}
else if (response && !response.error_message == "User+canceled+the+Dialog+flow") {
self.location.href = '/congrats'
}
});
After i'm done sharing this image with url :- http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id.
when I go to facebook and click on the image then everything works fine whether I click from facebook logged in from mobile browser or desktop browsers but when i go to facebook app and clicks on the link then it takes me to http://XX.XX.XXX.XXX:XXXX instead of http://XX.XX.XXX.XXX:XXXX/vacation_builders/" + vb_id.

Open app from link

Before I ask my question I know how to register url schema. This suggests the same. But this holds true if we have a custom url schema. What if we have to open a url with https schema. Not all https links. Ones only of my application. e.g. https://www.myurl.com or https://www.myurl.com/groups. I want that wherever I find these link on iPhone (email, SMS, Safari), my app should be opened.
You cannot control the https/https schema to redirect to an app as they are registered with browser.
So once User click on any http link it will launch the browser.
Approach that is widely used is to redirect from the browser to the app if it is installed.
You should redirect to the register url schema on your https url, and you can check the browser who is using the url by js, than match the redirect, like this:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
if ( isMobile.Android() ) {
document.location.href = "y";
}
else if(isMobile.iOS())
{
document.location.href="x";
}
And this link should help you also.

Javascript is not loaded after location.href

I've got this ajax request. Basically it downloads a file (after redirect to this page).
$.ajax({
url: '#Url.Action("IsFileSetForDownload", "UserLogin")',
success: function (result) {
if (result == "true")
top.location.href = "DownloadFile"
},
cache: false
});
Page also contains few input fields, some additional JS. Everything works fine. Except with IE8. After top.location.href javascript stops working (page is reloaded). Any ideas how to fix it?
A possible workaround is to create an iframe instead of redirecting the browser.
Simply replace:
if (result == "true")
top.location.href = "DownloadFile"
}
with:
if (result == "true")
var iframe = $("<iframe />").attr("src", "DownloadFile");
$("body").append(iframe);
}
This should result in the browser no longer assuming it's navigating to a new location.

Cookie not saving in safari when adding to home screen

Hey i'm using the following code to set a cookie and get it :
$.cookie('SimMobileUsername', $('#user_id').val());
if($.cookie('SimMobileUsername') != "null" && $.cookie('SimMobileUsername') != null); {
$('#user_id').val($.cookie('SimMobileUsername'));
}
Which works fine but when i add the webpage to the home screen it dosen't save the cookie.
Important:
I have read that safari caches home screen pages, so i tried the following code to refresh the page on 1 time on start but that didn't help either:
var url = window.location.href;
if (url.indexOf('rnd=') == -1) {
url = (url.indexOf("?") == -1 ? url + "?rnd=" : url + "&rnd=") + Math.random();
window.location.href = url;
}
Any insights on the subject?
In the end i solved it using localStorage in ios instead of cookie, if someone is to answer the question correctly i'll mark his as the right answer.

Resources