0

Hi guys I am having some weird problem with Firefox and IE. I haven't faced such problem before this so please help. I made a custom image browser to work with ckeditor. The browser(a popup window) window opens as expected but when when I try to return the fileUrl or run any type of javascript nothing happens in case of Firefox and IE. Everything's fine with chrome.

Browser page code:

<?php
     $path = "./public/user_images/demo_user/";
     if(is_dir($path) == true){
        $list = scandir($path);
        if(count($list) >= 1){
            foreach ($list as $key=>$value) {
               if(is_file($path.$value)){
                   $file = base_url($path.$value);
                   echo <<<start
                   <button class="btn_browser_img">
                      <img src="$file" class='browser_img'><img>
                    </button>
                    start;
               }
            }
         }
      }else{
          echo "Oops! Wrong folder...";
      }
?>

Background Javascript:

$(".browser_img").click(
function(){
    alert(this.getAttribute('src'));
    fileUrl = this.getAttribute('src');
    sendFileUrl(fileUrl);
}
);
function sendFileUrl(fileUrl){
  window.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl );
  window.close();
}
Manish Mishra
  • 12,163
  • 5
  • 35
  • 59
bytestorm
  • 1,411
  • 3
  • 20
  • 36

1 Answers1

1

this.getAttribute(...) will not work because this corresponds to the wrapper jQuery object.

So try this[0].getAttribute(...)

jQuery stores the actual object in the 0th location so this[0] will give you the DOM object.

collapsar
  • 17,010
  • 4
  • 35
  • 61
kcak11
  • 832
  • 7
  • 19
  • [the accepted answer to this SO post](http://stackoverflow.com/questions/10280250/getattribute-versus-element-object-properties) details some quirks you might encounter when using dom attributes instead of js properties. – collapsar Feb 19 '14 at 05:20
  • by the way, `this[0]` returns undefined only – bytestorm Feb 19 '14 at 05:24