Ads on our company's website dynamically generate JavaScript scripts in PHP and use PHP files directly as JavaScript files, usually on the home page with code like this
There's only one such sentence in this ad_js.php.
All other browsing did not appear to explain the file, except that Chrome interpreted it as HTML, meaning that there was only a bunch of comments left in the ad_js.php.
When I open Chrome's debugger a look that appears, such a warning:
Has anyone ever met a situation like this?
At present, my solution is directly echo that part of the JS code, but I want to maintain the original method.
Do you have a good way out?
Reply to discussion (solution)
You don't want to use it, but you still use echo.
Add type= "Text/javascript" Can you?
This PHP file needs to declare the type before output
Header (' Content-type:application/javascript ');
Otherwise, the default is declared as text/html, which naturally resolves to HTML format
As the source of the script tag, will it be interpreted as HTML?
The current situation is too bad, simple things have to be so complicated. I miss Microsoft's dominance of the world.
Style sheet requires text/css
JS needs Application/x-javascript
All returned files need to have a corresponding header description
As the source of the script tag, will it be interpreted as HTML?
The current situation is too bad, simple things have to be so complicated. I miss Microsoft's dominance of the world.
Style sheet requires text/css
JS needs Application/x-javascript
All returned files need to have a corresponding header description
It seems that it is not the problem, I can pass the test on other pages, I may be the JS code in a problem parsing problems