Error when trigger click event in IE6/IE7 (jquery) - internet-explorer-7

I have this code:
$("#boxId ul li a:eq(0)").click();
Works ok in IE8 and FF, but I'm getting error in IE6 and IE7.
"Object doesn't support this property or method"
Someone knows why?
Obs:
$("#boxFoto ul li a:eq(0)").size(); // returns '1'

There's no reason for jQuery's click() to fail on IE. I think the click event is actually triggered, but:
You have set an onclick handler on the hyperlink, and it tries to access a property or a method that's undefined under IE, or
You have an href="javascript:....." attribute on the hyperlink that has the same problem as above.

I found the error.
My code creates HTML dinamically, using this:
a.setAttribute("onclick","return false");
I changed to
a.onclick = function(){return false;};
And now works!
IE6/IE7 were returning the string "return false" in jquery code, not the function(){return false}. Somewhere in jquery code, I was getting "return false".apply(....., .....), that was the cause of the error Object doesn't support this property or method.

Related

Trying to write a logic to use browser back button click but inside $on not able to find 'this'

I am trying to go back to the previous page using angularJS when browser back button is clicked as it is not happening by default. I have written the below code and it is throwing an error.
something() {
this.scope.$on("$locationChangeStart",function(){
this.scope.transferTo('dashboard')
//$window.history.back();
});
}
I am calling something function in $onInit.
Error:
TypeError: Cannot read property 'scope' of null (getting this error 4 times)
Classic this binding issue.
Replace function(){} with () => {} or assign this to a variable, like let self = this.

$uibModal TypeError: Cannot read property 'close' of undefined

I am working in ServiceNow and have a button that pulls up a modal window that renders an embedded form. When a user submits, I have the embedded form $broadcast 'closeModal', and the button receives it to close. My client script looks like this for the embedded form:
$rootScope.$broadcast('closeModal');
and on my button that brings up the modal, my client script looks like this:
$rootScope.$on('closeModal', function() {
c.modalInstance.close();
});
This actually does close the modal window, but my console is showing "TypeError: Cannot read property 'close' of undefined"
Any idea why this is showing up?
Additionally, in my screenshot above, that typeerror actually shows up twice, for two different widgets. I am broadcasting and retrieving the same event for both widgets. I'm not sure if that's against best practice, but I've tried changing one of them to 'closeModal2' for example and the same typeError still shows.
Any suggestions or advice is greatly appreciated!
-- ADDED --
This is a screenshot of my console after logging c:
Simple hack is :
$rootScope.$on('closeModal', function() {
c.modalInstance && c.modalInstance.close();
});
Another suggestion is use $rootScope.$emit and listen at specific scope level $scope.$on

Testing a form in jasmine, Karma

I'd like to test a form in Jasmine, using Karma. When I enter wrong credentials and click the button, a notification appears with the appropriate message. Unfortunately, in the iframe in karma doesn't show this div, so the next expect fails because the selector does not match any element.
it('Testing a form', function () {
browser().navigateTo('/index.html');
input('firstName').enter('Wrong');
input('lastName').enter('Wrong');
element(':button.btn').click();
expect(element('.msg h1').text()).toMatch('Wrong Credentials');
}
The error I'm getting is
Selector .msg h1 did not match any elements.
When I use sleep(10) or pause() in order to see the form after the click event, the message is not appeared, that's why the selector doesn't match any element. Any idea please? Thank you very much!
1.You can create same form element inside test script using $compile service and test it by setting values of text boxes and hit $('button class').click();
And set spy on method which is showing error or success msg.So that you can understand if msg is being displayed or not.
2.You must be creating JSON out of form data and validating it or assigning that form data to any $scope.variable_name.Before invoking validation function explicitly set that variable with wrong input.Then call the function on button click or $scope.$emit('click'); and set spy on method used for showing error message.
You could try this;
Change expect(element('.msg h1').text()).toMatch('Wrong Credentials');
to
expect(element('[ng-view] .msg h1').text()).toMatch('Wrong Credentials');

How to avoid angular.js preemptively fetching data until certain actions

Just started out using angular.js and implemented a directive that reads from a property in the scope that's defined only when a button is clicked. The UI looks fine also because the directive part is only shown when the button is clicked. However in the console when the page is first loaded there is an error message saying "Cannot read property someProperty of undefined".
I must be violating some angular principles but I'm not sure how to fix it. Thanks for the help!
Note: Didn't do a fiddle because this is a general question.
Generally speaking, if you have code patten like
$scope.myObject.property
then you could see the error when myObject is undefined.
One possible way to eliminate the error the code work is make sure the object is always initialized when any property is intended to be referred.
You can put this line before the property is referred.
$scope.myObject = {};
Or do
if($scope.myObject !== undefined){
...
}
There is no rocket science here.

object error in ie7

How can i solve object error in ie7. Once i load my page. ie7 shows [object Error] in an alert box. i want to know why it happens and how to solve this.
(EDIT) this just in:
It now seems that IE7 sometimes displays this popup when an error occurs. It almost looks like it's trying to display an alert() with an object in it, called error. Here's how I found out. I was trying to set a table row's CSS display attribute to table-row, but after some debugging and internet seaching, I found out that IE7 and earlier do not support table-row as a display value. What I had:
document.getElementById('writeoff_tablerow').style.display = 'table-row';
What solved the problem:
try {
document.getElementById('writeoff_tablerow').style.display = 'table-row';
}
catch(e) {
document.getElementById('writeoff_tablerow').style.display = 'block';
}
(EARLIER ANSWER)
I've been stumped with this same thing today. Ultimately, the cause of the problem boiled down to the fact that I was using document.body.addEventListener to make the page respond to a mouse click:
document.body.addEventListener('click',function(){document.getElementById('blah_div_id').style.display='none';},false);
When I changed the code to the following, the problem was gone in IE7:
document.body.onclick=function(){document.getElementById('blah_div_id').style.display='none';};
post some code, otherwise we cant help you.
try the website in Firefox with Firebug installed, and maybe you will get additional information in the console there (if the problem is in FF as well, that is)
Since i am using Protovis Graph library. This is cause for my error. Since Protovis is not compactable with ie7 it araise object error.

Resources