diff --git a/tweetbutton.module b/tweetbutton.module
index 400cf0b..966cda2 100644
--- a/tweetbutton.module
+++ b/tweetbutton.module
@@ -389,7 +389,7 @@ function tweetbutton_tweet_get_attributes($options = array()) {
 
 
 function theme_tweetbutton_tweet_display($variables) {
-  $script_url = url('http://platform.twitter.com/widgets.js', array('external' => TRUE, 'https' => TRUE));
+  $script_url = _tweetbutton_get_widgets_js_url();
   drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer'));
   $options = $variables['options'];
   $attributes = tweetbutton_tweet_get_attributes($options);
@@ -424,7 +424,7 @@ function tweetbutton_follow_get_attributes($options) {
 }
 
 function theme_tweetbutton_follow_display($variables) {
-  $script_url = url('http://platform.twitter.com/widgets.js', array('external' => TRUE, 'https' => TRUE));
+  $script_url = _tweetbutton_get_widgets_js_url();
   drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer'));
   
   $options = $variables['options'];
@@ -459,7 +459,7 @@ function tweetbutton_hashtag_get_attributes($options) {
 }
 
 function theme_tweetbutton_hashtag_display($variables) {
-  $script_url = url('http://platform.twitter.com/widgets.js', array('external' => TRUE));
+  $script_url = _tweetbutton_get_widgets_js_url();
   drupal_add_js($script_url, array('type' => 'external', 'scope' => 'footer'));
   
   $options = $variables['options'];
@@ -475,4 +475,11 @@ function theme_tweetbutton_hashtag_display($variables) {
   
   $hash_link = l($hash_text, 'http://twitter.com/intent/tweet', array('query' => $query, 'attributes' => $attributes, 'external' => TRUE, 'https' => TRUE));
   return '<div class="tweetbutton-hashtag tweetbutton">' . $hash_link . '</div>';
+}
+
+function _tweetbutton_get_widgets_js_url() {
+  global $base_url;
+  $connection = strpos($base_url, 'https://') === 0 ? 'https' : 'http';
+  $script_url = url($connection.'://platform.twitter.com/widgets.js', array('external' => TRUE));
+  return $script_url;
 }
\ No newline at end of file
