1

Possible Duplicate:
using php to check is a javascript file has been loaded?

Is it possible to check if the js file is already loaded in a page using PHP? Because I have some block on my page that needs the js file. So if the js file is not loaded then don't load this block.

It's something like this:

if js file is not loaded then don't execute this php script else execute this php script

1

2 Answers 2

4

You can't.

PHP sends an HTML document to the client then the client then handles the HTML and makes HTTP requests for any JavaScript files.

Redesign the block that depends on the JS to make use of progressive enhancement. Writing your JS so it is unobtrusive will help with this.

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

2 Comments

Thank you very much for the info. If it's not possible, is there a way to run javascript even there are so many plugin like in firefox to prevent javascript from running? Is ajax the answer for this? Can ajax run even there are plugin that preven javascript from running on a page?
No. User preferences to block JavaScript would be pointless if pages could override them. Ajax is a buzzword that means, more or less, "Using JavaScript to make HTTP requests" so you can't use it without JavaScript.
0

You could keep track of successful JS files in cookies or pass the details to future PHP files. Otherwise, PHP is server side and JS is client side.

1 Comment

thank you. you give me a clue. i created a cookie then check it using php if it was loaded. if not meaning the js script is not loaded too.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.