0

I'm trying to prevent a javascript file from loading if a user is on an iPhone. I'm using the Mobile ESP script for the detection, I'm just not sure what to add to this file to remove the unwanted file from loading.

In other words, what do I add to this file:

js/detect.js

…to prevent my page from loading the file:

js/jquery.ceebox-min.js
2
  • Maybe not prevent from loading if on iPhone but load if not on iPhone. Should be easier. Commented May 27, 2011 at 17:38
  • Maybe if you gave more details about why you want to do this, we could answer your question better. Have you considered only loading the files you need, instead of trying to stop files you don't need? Commented May 27, 2011 at 17:41

3 Answers 3

3

I think better than preventing loading if it is an iphone, you can only load if it is not an iphone, for that there's jQuerys getScript.

Sign up to request clarification or add additional context in comments.

Comments

1

This seems like something that would best be handled by whatever preprocessor you're using, be it PHP, Ruby, Python etc...

As pointed out in another answer having detect.js load only the required js files using $.getScript() would be another way to do it.

Comments

1

There was another question from a while ago along similar lines. And the basic answer that I stumbled upon was that, by the very nature of how some browsers work, it's not at all possible. I'm not sure if iPhone's browser is the same, but Chrome seems to download all the scripts before it starts executing them.

The example I made for that other question was something along these lines:

<script src="first.js"></script>
<script src="second.js"></script>

The second.js was just a simple alert, to see if it loaded or not.

The first.js script had a synchronous AJAX request that told PHP to delete second.js. The reasoning was that PHP could delete the file, and then the browser would request it, but get a 404 error.

But (on Chrome, anyway) the second script was still executed. Even when the first script deleted the file from the server, it still executed.

Not possible.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.