Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught TypeError: Cannot read property 'safari' of undefined

I have this jjavascript to resize iframes:

 $(function () {

            var iFrames = $('iframe');

            function iResize() {

                for (var i = 0, j = iFrames.length; i < j; i++) {
                    iFrames[i].style.height = iFrames[i].contentWindow.document.body.offsetHeight + 'px';
                }
            }

            if ($.browser.safari || $.browser.opera) {

                iFrames.load(function () {
                    setTimeout(iResize, 0);
                });

                for (var i = 0, j = iFrames.length; i < j; i++) {
                    var iSource = iFrames[i].src;
                    iFrames[i].src = '';
                    iFrames[i].src = iSource;
                }

            } else {
                iFrames.load(function () {
                    this.style.height = this.contentWindow.document.body.offsetHeight + 'px';
                });
            }

        });

In chrome, it has trouble here:

 if ($.browser.safari || $.browser.opera) {

Is there any reason why I get this error? I am using the latest JQuery?

Thanks

like image 897
user2043533 Avatar asked Feb 21 '13 20:02

user2043533


2 Answers

You are probably using jQuery 1.9 or above, in which case $.browser was officially removed after being deprecated since 1.3.

You can use jQuery migrate which will patch it, but it's better to move to a feature specific approach instead of browser specific approach. Modernizr is great for this.

like image 70
Michael Marr Avatar answered Nov 15 '22 22:11

Michael Marr


jquery recommends against $.browser... use $.support instead..

if $.browser.safari (or opera or whatever your trying to access) doesn't exist it throws an error. check if its undefined

like image 45
Gokul Kav Avatar answered Nov 15 '22 22:11

Gokul Kav