I am facing following strange issue:
Functionality:
When I open my website page which has many images and have Javascript/jQuery used for client side functionality. On clicking each image, all the other images changes their opacity and the selected image shows a <div> containing some information and a video for the image.
- I have used jQuery unveil which loads all the images only after a scroll event is fired on the page. Until that, it displays a "loading" image.
- I have added a Javascipt on
window.onloadevent to resize the<div>element when image is clicked. And some Javascript that identifies the browser and set video tag source accordingly. - All the images are rendered inside a datalist and is being bound from database.
- As unveil loads the image only after scroll event, I have added a code on page load to scroll a page by a pixel artificially.
Problem:
I open the same page in iPad(iOS 8.4) on Chrome or Safari. All my Javascript under window.onload does not fire.
ASPX page:
<script type="text/javascript" src="/js/jquery.unveil.js"></script>
<asp:DataList ID="dlPersonList" runat="server" OnItemDataBound="dlPersonList_OnItemDataBound"
RepeatDirection="Horizontal" RepeatLayout="Flow">
<ItemTemplate>
<div class="itemImage">
<asp:HyperLink ID="hypPersonPicture" runat="server">
<asp:Image ID="imgPersonPicture" runat="server" CssClass="lazy" />
</asp:HyperLink>
</div>
<asp:Panel class="person-detail" ID="pnlpersonDetail" runat="server">
<div class="person-content detailView">
<%--Some text and other controls--%>
<asp:Panel ID="pnlVideo" runat="server">
<div class="video-content">
<video id="personVideo" controls="controls" preload="none">
<%--Video source elements--%>
</video>
</div>
</asp:Panel>
</div>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
CS code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//Bind data list
dlPersonList.DataSource = SelectPersons();
dlPersonList.DataBind();
// Register the script for slide up effect
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptPerson", @"$(document).ready(function () {
jWDScrollWindow();});",
true);
}
}
protected void dlPersonList_OnItemDataBound(Object sender, DataListItemEventArgs e)
{
/*Lazy loading functionality*/
//Set the image source as loader image
imgPersonPicture.Attributes.Add("src", "/img/loading.gif");
//set image resource as actual image
imgPersonPicture.Attributes.Add("data-src", imageObject.ImagePath.TrimStart('~'));
}
JS code:
window.onload = function () {
//Apply lazy loading functionality to images
$(".lazy").unveil();
//Javascript to set the width and height of the details div
.
.
//Javascript to blur all the other images when one image is clicked
}
function jWDScrollWindow() {
//scroll by 1px to load the images
$(window).scrollTop($(window).scrollTop() + 1);
}
Things I have tried yet:
- I thought jQuery unveil might have making the page slow or something. so, I removed the call but the problem is the
unveil();is called withinwindow.onload. So, ifwindow.onloadis not being fired, it doesn't make any sense to remove the unveil. - I added an
alert()onwindow.onload(), but in this case, everything works perfectly.
All the functionality works perfectly in all devices except ipad with ios 8.4 (it works great even in earlier os)
Help/Suggessions are much appreciated.
EDIT:
I found one jsconsole through which we can see the console logs in iPad on the desktop. Here is how we can use it.
I checked the logs and found that when I am getting error JQMIGRATE: jQuery.browser is deprecated, My window.onload event doesn't fire. Whereas, if I get log JQMIGRATE: Logging is active, everything works fine.
My jqmigrate reference is in master page as,
<script type="text/javascript" async src='/js/jquery-migrate-1.1.1.js'></script>