2016-08-10 5 views
1

私は一度クリックして新しいコンテンツを表示するとTwitterボタンを隠す方法を検討しています。誰かが私の間違いを指摘して助けになるのであれば、なぜ私は確信していません。おかげさまで 一度つぶやきを表示して非表示にする

---- UPDATE ----

その私はそれが

<script type="text/javascript" src="//platform.twitter.com/widgets.js"></script> 

<script src="https://code.jquery.com/jquery-1.12.4.js"></script> 

----更新終了を動作を停止し、このスクリプトを追加するとき----

H EREコードです:UPDATE

(function($) { 
 

 
    var win = null; 
 

 
    $.fn.tweetAction = function(options, callback) { 
 

 
    // Default parameters of the tweet popup: 
 

 
    options = $.extend({ 
 
     url: window.location.href 
 
    }, options); 
 

 
    return this.click(function(e) { 
 

 
     if (win) { 
 
     // If a popup window is already shown, 
 
     // do nothing; 
 
     e.preventDefault(); 
 
     return; 
 
     } 
 

 
     var width = 550, 
 
     height = 350, 
 
     top = (window.screen.height - height)/2, 
 
     left = (window.screen.width - width)/2; 
 

 
     var config = [ 
 
     'scrollbars=yes', 'resizable=yes', 'toolbar=no', 'location=yes', 
 
     'width=' + width, 'height=' + height, 'left=' + left, 'top=' + top 
 
     ].join(','); 
 

 
     // Opening a popup window pointing to the twitter intent API: 
 
     win = window.open('http://twitter.com/intent/tweet?' + $.param(options), 
 
     'TweetWindow', config); 
 

 
     // Checking whether the window is closed every 100 milliseconds. 
 
     (function checkWindow() { 
 

 
     try { 
 
      // Opera raises a security exception, so we 
 
      // need to put this code in a try/catch: 
 

 
      if (!win || win.closed) { 
 
      throw "Closed!"; 
 
      } else { 
 
      setTimeout(checkWindow, 100); 
 
      } 
 
     } catch (e) { 
 
      // Executing the callback, passed 
 
      // as an argument to the plugin. 
 

 
      win = null; 
 
      callback(); 
 
     } 
 

 
     })(); 
 

 
     e.preventDefault(); 
 
    }); 
 
    }; 
 

 
})(jQuery); 
 

 
$(document).ready(function() { 
 

 
    $('#tweetLink').tweetAction({ 
 
    text: 'First tweet', 
 
    url: '#', 
 
    via: 'website' 
 
    }, function() { 
 

 

 
    $('hidden-text') 
 
     .show(); 
 

 
    $(".hidden-text").removeClass("hidden-text"); 
 

 

 
    }); 
 

 
}); 
 

 
$(document).ready(function() { 
 
    $("p").click(function() { 
 
    $(this).hide("slow"); 
 
    }); 
 
});
.hidden-text { 
 
    display: none; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<p>Tweet to show content. 
 
    <a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button" id="tweetLink" data-show-count="false">Tweet to @your_twitter</a> 
 
      </p> 
 
      <p class="hidden-text">thank you for tweeting !</p>

最適化されたいくつかのJS

$(document).ready(function() { 

$('#tweetLink').tweetAction({ 
    text: 'First tweet', 
    url: '#', 
    via: 'website' 
}, function() { 

    $('hidden-text') 
     .show("slow"); 

    $(".hidden-text").removeClass("hidden-text"); 
    $("#hide-me").hide("slow"); 
}); 

})。私はそれを@your_twitterするツイートをクリックして今開いていない線量とき、私は、私のjQueryのCDNを更新した私は、エラー

Uncaught TypeError: $(...).tweetAction is not a function 

を取得しているように見えるコンソールを見て

UPDATE 3

[OK]を新しいウィンドウで同じウィンドウ内のURLを変更します。何か案は ?

を解決し、私はいくつかのCDNの

<link href="https://get.gridsetapp.com/35679/" rel="stylesheet"/> 
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css"> 
<!--<script src="https://code.jquery.com/jquery-1.12.4.js"></script> --> 
<!--<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.min.js"></script>--> 
<!--<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>--> 


<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script> 
<!--<script src="https://code.jquery.com/jquery-3.1.0.min.js" ></script>--> 
+0

コードをスニペットとして使用するように質問を編集しましたが、正常に動作しているようです...さまざまなブラウザをテストしましたか? – andreas

+0

ええ、最近のクロムには、もう一度やり直してください。おかげで –

+0

ああ、私は問題を発見した、アップデートを参照してください –

答えて

1

これらのスクリプトを追加するときに機能しなくなった場合は、スクリプトを1つずつ追加し、jsコンソールでエラーがないか確認してください。これは、エラーを検索する場所を知るヒントを与えるはずです。

これらのライブラリが2回ロードされていないかどうかを確認してください。たとえば、別のjQueryライブラリを既にロードしている場合は、動作しません。

+1

ありがとう、私はこれを行い、あなたに戻って+1 –

-1

を削除しなければならなかった私はここ2つの構文を参照してくださいが、彼らはあなたの問題を行う必要はありません。

<a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button" 
       id="tweetLink" data-show-count="false">Tweet to @your_twitter/a><a href="https://twitter.com/intent/tweet?screen_name=your_twitter" class="twitter-mention-button" 
       id="tweetLink" data-show-count="false">Tweet to @your_twitter </a> <!--Closing the tag--> 

$('.hidden-text').show(); //class picker 
関連する問題