diff --git a/imce_filefield.inc b/imce_filefield.inc
index e1557aa..1e4b5a5 100644
--- a/imce_filefield.inc
+++ b/imce_filefield.inc
@@ -118,7 +118,7 @@ function _imce_filefield_field_value($element, &$item, &$form_state) {
  * Pre render callback. Add page elements.
  */
 function _imce_filefield_field_pre_render(&$element) {
-  imce_filefield_jscss();
+  imce_filefield_jscss($element);
   $jset['imce_filefield']['fields'][$element['#id']] = array('path' => $element['#entity_type']  . '/' . $element['#bundle'] . '/' . $element['#field_name']);
   drupal_add_js($jset, 'setting');
   if (!empty($element['#value']['fid'])) {
@@ -153,14 +153,20 @@ function imce_filefield_element_validate($element, $file) {
 /**
  * Adds main js, css files and settings.
  */
-function imce_filefield_jscss() {
+function imce_filefield_jscss(&$element) {
   static $done;
   if (!isset($done)) {
     $done = TRUE;
+    $url = preg_replace('/.*:\/\//', '', $element['#upload_location']);
+    $url = $url ? $url : '.';
     $path = drupal_get_path('module', 'imce_filefield');
     drupal_add_css($path . '/imce_filefield.css');
     drupal_add_js($path . '/imce_filefield.js');
-    drupal_add_js(array('imce_filefield' => array('url' => url('imce-filefield'), 'token' => drupal_get_token('imce_filefield'))), 'setting');
+    drupal_add_js(array('imce_filefield' => array(
+      'url' => url('imce-filefield'),
+      'token' => drupal_get_token('imce_filefield'),
+      'dir' => $url,
+    )), 'setting');
   }
 }
 
@@ -199,4 +205,4 @@ function _imce_js_imce_filefield(&$imce) {
       return array('fid' => empty($file->fid) ? 0 : $file->fid);
     }
   }
-}
\ No newline at end of file
+}
diff --git a/imce_filefield.js b/imce_filefield.js
index 0de1864..17a271b 100644
--- a/imce_filefield.js
+++ b/imce_filefield.js
@@ -20,7 +20,7 @@ Drupal.behaviors.imce_filefield = {attach: function(context, settings) {
     // IMCE opener link.
     var $opener = $(document.createElement('a')).addClass('imce-filefield-opener').attr({href: '#'});
     $opener.text(imce_filefield.openerText()).click(function() {
-      window.open(set.url + '/' + conf.path + (set.url.indexOf('?') < 0 ? '?' : '&') + 'app=imce_filefield|sendto@imce_filefield.sendto&fieldID=' + fieldID, '', 'width=760,height=560,resizable=1');
+      window.open(set.url + '/' + conf.path + (set.url.indexOf('?') < 0 ? '?' : '&') + 'app=imce_filefield|sendto@imce_filefield.sendto&fieldID=' + fieldID + '&dir=' + set.dir, '', 'width=760,height=560,resizable=1');
       return false;
     });
     // Add elements to document.
@@ -83,4 +83,4 @@ imce_filefield.openerText = function() {
   return Drupal.t('Open File Browser');
 };
 
-})(jQuery);
\ No newline at end of file
+})(jQuery);
