I have a code which uses the jquery $(document).ready()
method and is evaluating a click on an item.
Im a PC everything works fine, but the target group of my page are smartphone users. With a smartphone the behaviour of this script is erratic and I suspect that above named $(document).ready()
is the culprit.
What can I do?
First option: Put my code back into the HTML code instead of loading a script file in the header of my page? So I can be sure the code is there? Possible but ugly and messy.
Second option: Substitute $(document).ready()
with something else? If yes with what? I am not using jquery mobile yet and until now it wasn't necessary and I hesitate to implement it just to make one line work.
Has someone an idea how to deal with this?
Here is part of my code:
var track = function (myLink, func) {
var redirectUrl = myLink;
alert(redirectUrl);
// Do things here....
//Call ajax with parameters set before...
$.ajax({
type: "GET",
url: sUrl, // Url to webservice
data: clickdata, // Data to be send to webservice
dataType: "text",
timeout: 100,
complete: func
}
);
}
// Show loading gif and track clicks on banners.
$( document).ready(function(){
function loading_anchor(e) {
e.preventDefault();
var qa = $(this);
function loading_bar() {
window.location = redirectUrl;
// Show loading bar everytime we load a after a click.
// Not important code here....
}
var redirectUrl = e.currentTarget.href;
if (qa.hasClass("previewlink") || qa.hasClass("productbanner")) {
// In case of a click on a banner we want to track this click.
track(this, loading_bar);
}
loading_bar();
}
$('a[loading="1"]').click(loading_anchor);
});
What should happen here ( and mind me happens perfectly on a pc) is tracking the click on certain items through calling a webservice. The webservice gives nothing back and I don't need anything from it. After the call the default behaviour is executed: forwarding to the link target and while still lingering on the present page I show a loading gif.