-4

任何人都可以知道我如何从我的网站 truebatteries.com 中删除额外的 javascript 代码

那么,从 SEO 的角度来看,我如何从网站中删除 javascript 代码,这对我们来说太糟糕了..

例子

请看看我们是否可以通过 HTTP 请求将此内部 JAVASCRIPT 代码变为外部文件或将其完全删除

Here is the INTERNAL JAVASCRIPT for CURRENCY CONVERTER that can be found on the site.


<scripttype="text/javascript">

  function get_url_var(url_var) {

    varurlHalves = String(document.location).toLowerCase().split('?');
    varurlVarValue = '';

    if (urlHalves[1]) {
           varurlVars = urlHalves[1].split('&');

           for (var i = 0; i <= (urlVars.length); i++) {
                   if (urlVars[i]) {
                           varurlVarPair = urlVars[i].split('=');

                           if (urlVarPair[0] &&urlVarPair[0] == url_var.toLowerCase()) {
                                  urlVarValue = urlVarPair[1];
                           }
                   }
           }
    }

    return urlVarValue;
    } 


$(document).ready(function () {



    $('#bussoc-paypal-express').live('click', function() {
           $.ajax({
                   url: 'https://www.genuinebatteries.com/payment/bussoc_paypal_express/init',
                   type: 'get',
                   dataType: 'json',
                   success: function(json) {
                           $('.success, .warning, .attention, information, .error').remove();

                           if (json['error']) {

                                  if (json['error']) {
                                          $('#notification').html('<div class="warning" style="display: none;">' + json['error'] + '<imgsrc="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>');

                                          $('.warning').fadeIn('slow');
                                  }
                           }       

if (json['redirect']) {
                                  location = json['redirect'];
                           }       
                   }
           });            
    });     




    if (get_url_var('route') == 'checkout/cart') {
           varobj = $('#content h1');
        if (obj != undefined ) {
           $(obj).append('<div style="float:right; margin-top:6px;"><a id="bussoc-paypal-express" ><imgsrc="catalog/view/theme/default/image/btn_xpressCheckout.gif" alt="Paypal Express" /></a></div>');
        }
    }
           });

感谢您的回复,我按照您的指示做了,但它不起作用,以下是我需要从货币转换器模块的内部文件移入外部文件的代码,请参阅 tpl 文件的代码

javascript代码在最后,然后我将它移动到另一个文件并像这样引用它,请参阅....

<div class="box">

<div class="box-currency">

    <div class="c-amount">

        <?php echo $text_amount; ?>

        <input style="text-align:right" type="text" size="10" value="<?php echo $currency_value; ?>" name="currency_value"/>

    </div>

    <div class="c-from">

        <?php echo $text_from; ?><br />

        <select  style="max-width:160px" name="currency_from">

                    <?php foreach($currencies as $currency){ ?>

                        <option <?php echo ($currency['currency_code'] == $currency_from) ? 'selected="selected"' : ''; ?> value="<?php echo $currency['currency_code']; ?>"><?php echo $currency['currency_name'].'('.$currency['country_code'].')';?></option>

                    <?php } ?>

                </select>

    </div>

    <div class="c-to">

        <?php echo $text_to;?><br />

        <select style="max-width:160px" name="currency_to">

                    <?php foreach($currencies as $currency){ ?>

                        <option <?php echo ($currency['currency_code'] == $currency_to) ? 'selected="selected"' : ''; ?> value="<?php echo $currency['currency_code']; ?>"><?php echo $currency['currency_name'].'('.$currency['country_code'].')';?></option>

                    <?php } ?>

                </select>

    </div><br />

    <div style="text-align:center" class="converter">

    <div id="c-loadding"></div>

    <a class="button" id="goconverter" ><span><?php echo $text_converter;?></span></a>

    </div><br />

    <div class="c-results">

     <p class="prices"> <?php echo $currency_value.$currency_from.' = '.$currencyconverter['amount'].$currency_to; ?></p>

     <p style="font-size:10px"><?php echo $text_rate.$currencyconverter['date'].' '.$currencyconverter['time']; ?></p>

    </div>

</div>

Javascript代码如下,我从底部的上方文件中获取

<script type="text/javascript"><!--

$('a#goconverter').bind('click',function(){

$.ajax({

    type: 'POST',

    url: 'index.php?route=module/currencyconverter',

    data: 'currency_value=' + encodeURIComponent($('input[name=\'currency_value\']').val()) + '&currency_from=' + encodeURIComponent($('select[name=\'currency_from\']').val()) + '&currency_to=' + encodeURIComponent($('select[name=\'currency_to\']').val()),

    dataType: 'json',

    beforeSend: function() {

    $('#c-loadding').html('<img src="catalog/view/theme/default/image/loading.gif" id="loading" style="padding-left: 5px;" />');

},

    success:function(json){

        if(json.error)

        {

            $('.c-results').html('<p style="color:red">'+json.error+'</p>');

            $('#c-loadding').html('');

        }

        if(json.currencyconverter)

        {

            var html = '';

            html += '<p class="prices">';

            html += json.currency_value + json.currency_from;

            html += ' = '+ json.currencyconverter['amount'] +'';

            html += json.currency_to;

            html += '</p>';

            html += '<p style="font-size:10px">';

            html += '<?php echo $text_rate; ?>';

            html += json.currencyconverter['date']+json.currencyconverter['time'];

            html += '</p>';

            $('.c-results').html(html);

            $('#c-loadding').html('');

        }

    }

})

});

//-->

4

3 回答 3

4

将 JavaScript 放在网络服务器上的单独文件中,然后将其包含在脚本标记中,例如:

<script type="text/javascript" src="path/to/script.js"></script>

虽然我非常怀疑这会对 SEO 产生任何影响。

于 2012-07-25T18:28:42.850 回答
1

不确定你的问题是什么,但我认为:

  1. 将所有脚本(不是 html 标记)放入另一个扩展名为 .js 的文件中。

  2. 将这样的链接放入您的页面:

<script type="text/javascript" src="MyNewFile.js"></script>

这应该允许您的页面以相同的方式工作,并允许您的用户在提供页面时可能缓存此文件。

于 2012-07-25T18:30:08.630 回答
0

如果您只是不希望它与您的 html 内联,请创建一个新文件,currencyConverter.js将所有内容放在此文件中,并在您的 html 中添加对它的引用,例如:

<script type="text/javascript" src="/js/currencyConverter.js"></script>

将所有 javascript 放在一个公共位置是个好主意,即jsweb 根目录下的目录

于 2012-07-25T18:31:12.007 回答