简体   繁体   中英

Webhoster inserts a javascript which brokes my code how to remove it?

I use the free webhost 000webhost. The service is okay but it inserts some javascript counter into every file and request. The script looks like this.

<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

If i do a jquery post it breaks my code and I get no response.

<?xml version="1.0"?>
<response>
 <status>1</status>
 <time>1266267386</time>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>test</author>
  <text>hallo</text>
 </message>
 <message>
  <author>admin</author>
  <text>hallo</text>
 </message>
</response>
<!-- www.000webhost.com Analytics Code -->
<script type="text/javascript" src="http://analytics.hosting24.com/count.php"></script>
<noscript><a href="http://www.hosting24.com/"><img src="http://analytics.hosting24.com/count.php" alt="web hosting" /></a></noscript>
<!-- End Of Analytics Code -->

How can I fix that? How can I remove the hosting javascript code?

They have a link in their cPanel where you can disable the analytics code.

http://members.000webhost.com/analytics.php

EDIT

Beware - by doing this you violate their policy and they will eventually drop you from their service and you will lose all your data.

In case anyone run into this problem in the future, to stop the analytic code from being included, all you have to do is use the exit() command at the end of your script. The code is in a PHP auto-append file. It doesn't get executed if you exit explicitly instead of letting the script reach the end of the file. The setup at 000webhost.com parses HTML through PHP as well. If you want your regular HTML files to pass validation, add at the very end the following:

<?php exit; ?>

Adding to Catfish's answer,

They have a link in their cPanel where you can disable the analytics code.

http://members.000webhost.com/analytics.php

EDIT

Beware - by doing this you violate their policy and they will eventually drop you from their service and you will lose all your data.

As asked by asalamon74 in the comments,

When I disable the analytics code with this method my domain get canceled due to inactivity. Is there a way to avoid it

Yes, there is a simple way to avoid it. Go ahead and enable your analytics code. Visit http://members.000webhost.com/analytics.php and enable it again.

Then, create a .htaccess in your public_html folder and add the following code to it:

<FilesMatch "\.(php)$">
php_value auto_append_file none
</FilesMatch>

This will prevent all .php files from been appended with the analytics code. Just replace php with any file extension where you want the analytics code removed.

That's all. This way your domain won't get cancelled. Hope it helps.

According to the FAQ, you can go to http://members.000webhost.com/analytics.php to disable the analytics:

How to disable analytic code from my site? (Note: in some case you might need to add this "php_value auto_append_file none" to your .htaccess)


Alternatively, you could edit your .htaccess file by adding this line:

php_value auto_append_file none

Try changing the content-type in PHP; that should help. (For example, I assume, it doesn't modify images)

Alternatively, you could remove the code in Javascript using indexOf and substring .

Check the terms of service agreement for your host. They may require their analytics code to run unadulterated as part of your TOS.

If they require this code to run, then there are 2 possible solutions:

  • Get a new host (see http://www.webhostingtalk.com for hosting reviews and deals)
  • Figure out what in your code is being affected and find a work around there.

If they do not require the analytics code block as a condition of service then you may be able to block their snippet from running by altering the tag's event handler via jquery that they use to fire their code.

If you are using the $.ajax(); function, there is a dataFilter parameter that lets you modify the raw contents of the request before processing it. In here, you could either substring or replace out the offending text, or you could add a <!-- to the end of your XML file, then stick a --> at the end of the response in the dataFilter code.

The analytics code also creates 3 html errors when checked with the w3c validator, so this also lowers your website ranking with google, as google say their ranking also requires that your pages are well formed! try using the validator on this page HERE and you will see the 3 errors.

I had EXACTLY the same problem with these guys. I was so confounded as Chrome just said there was a problem, but thankfully I tried Firefox and it actually blurted out the offending code. I talked to customer support about it, and they said they don't add content to customer pages. Seriously?! So the solution is, as suggested by others, move on and get someone better.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM