Member not found error in java script - javascript

The below code for opening and closing a window is throwing a java script error 'Member not found'. This does not happen in all machines but for certain users with IE 8.
winobject.blur() in the following code is throwing the error.
var winobject=null;
winobject = window.open('URL','Name',"width=1,height=1,top=2000,left=2000");
if(winobject!=null){
winobject.blur();
self.resizeTo(screen.availWidth,screen.availHeight);
winobject.close();
...
}
Any help or suggestion to resolve this issue?
Some additional observations- This issue only occurs when a window with the 'Name' already exists. Lets say if the user has already closed the pop up window that was already opened then the code will run fine. Also if I add one more window.open under the current one then no exception gets thrown when blur() is invoked. Not sure why though ?

if (typeof winobject != "undefined")
I just had an issue with something like this at work today. give that a try, you should be good to go.
Edit:
I have found the following link which appears to explain what is going on. Because you are creating that window on your own, IE8's "security" is preventing many common actions on it.
My next suggestion as a workaround would be to surround both the winobject.blur() and winobject.close() with if (winobject.blur) and if (winobject.close()) conditionals. Note that you do not have the parenthesis after blur and close in the if's, as you are looking for the presence of the method as opposed to calling the method.
Unfortunately, I'm not sure what the alternatives are that you can use to obtain the same effect. But that should hopefully prevent the error from being thrown.

Related

Is there any chance to find source of javascript alert?

I'm working in a large project that was developed for several years and had tons of code. Recently uninformative alert start to appear. It just says Undefined. I need to find the source of this alert. Is the any chance to make something like "breakpoint on alert"? I want to see the source of this alert.
One possibility is to redefine alert function. I tried to make it in firefox without any success.
I'd go with redefining window.alert right at the start of the code for this type of development purposes.
window.alert = function(e){ console.warn( "Alerted: " + e ); }
This will give You a line number for sure. ( Tested on chrome console )
This is an old question, but thought I would help out with a simpler solution. A very easy way in Chrome to find the source is by placing a debug in the console on window.alert:
debug(window.alert)
This will break on alert and take you to the source. In general, using console with debug(fname) will break whenever the function fname is called.
As a continuation to Vsevolod's method, in FireBug over Firefox for example, you could place one conditional breakpoint on each and every alert(), and see which one fires off, then go up the callstack shown by FireBug.
The condition could be "typeof whatever_variable_is_displayed == 'undefined'".

Open link in popup window

I might be tired but I just can't figure out what the problem is. What I'm trying to do is open a link in a popup window. I got this code below working before but I removed it.
About
However, it stopped working now when I put it back. I even got it working on jsFiddle so I'm at lost on what to do. I'm assuming something must be blocking it from running?
The code is short and simple so I figured someone here might have an idea what could cause this.
EDIT: Sorry I should have thought of it. I guess I should sleep. Anyway here's a demo-website where I reproduced the problem http://testmycode.tumblr.com/ The problem is the "About" link, pressing it returns nothing.
OK, it seems like somewhere in your code you have changed the window variable to a custom function. When you try to call window.open (more specifically, document.window.open), the method open simply doesn't exist in the function window, which causes it to throw an error.
Check this out:
You somewhere changed it to a function by doing document.window = ....
It's MooTools 1.2.4 which changed it:
To fix it, simply using an EventListener and problem solved! (Inline codes are bad practice anyway.)
<a class="about">About</a>
$(".about")attr("href", "#").click(function(e){
window.open(...);
e.preventDefault();
});
The snippet you shared works when I append it to the page we are at, in Google Chrome. Which makes me wonder which browser you are having the trouble in. So I would encourage you to try the snippet you shared in Google Chrome, and if it works there then you will know it is a browser specific kind of bug, in which case I would try adding a semicolon after return false.

TinyMCE fails silently

How do I set debug mode or similar in TinyMCE?
When there are errors (for example undefined references) in custom setup functions or somewhere else, all my script stops and I don't see a single line appearing in the console.
Didn't find anything searching, maybe I'm not seeing the obvious again... can't be that difficult...
Thanks!
Yes, you are right. Unfortunately, there is only the way of using try-catch blocks in custom setup functions.

How to open a window in asp:updatepanel

I have a pop-up CustomControl which I use in a large-scale web application. The pop-up works well everywhere other than when used inside an asp:UpdatePanel, the problem arises when controlling the visibility of the pop-up (the pop-up is nested in a table) with other controls:
When I click the button to open the window I get Error: Object expected and when I try to debug the error with IE 8 JSEditor I get ``Source Code is not available for this location.
I believe that the code of the pop-up is not being initialized completely, but it is just my guess and I don't know how to resolve this issue.
Any help or ideas will be appreciated.
While I can't get to see that question title has a lot to do with the subject at hand,
Most (if not all) Object Expected error occurs when you add a reference on your page to a JavaScript file which doesn't exist or cannot be opened.
When you run your website in debug-mode, VS will put another pseudo-project in solution explorer, navigate through the files there and you will find the already loaded-version of JS, you can set breakpoints there and see what code exactly is "not available".
Note: This is for Web Applications, I'm not sure if it applies to Project-less Websites.
Does this work in other browsers? Have you tried Firefox and Firebug to investigate the issue or is this specific to IE.
Having code in an ASP:UpdatePanel means that the Microsoft Ajax javascript include will be loaded and come an interfere with the object model you are normally expecting to get. Are you certain of the id or name you are trying to find as this might not be returning an Object hence the error.
I have used jQuery and classes and styles to add behaviour after the page loads to avoid id issues. The $jQuery.live() function is useful to ensure handlers get bound to items delivered to the page with MS Ajax.

Detecting cause of IE's Operation Aborted Issue

My site is suffering from the Operation Aborted error. What I find weird is that in my case the error only sometimes happens. The site has been running fine for three months then today it starts happening but not every time.
The page this is occuring on is rather large with a lot of third party controls. What I'd like is a tool that could pinpoint where the failure is occuring. Seems like the best I can do is find the first javascript error that occurs after the operation aborted; however, this doesn't help much. This failure is because an element of the dom isn't available which I'd expect since IE stopped parsing the HTML.
Any one have any ideas or tricks to narrow this down?
Edit
I appreciate additional ways to resolve the issue; however, what I am looking for is a way to identify which script is causing the issue.
Final Edit
After switching to IE8, I was able to determine the cause was the AjaxControl Toolkit's modal popup dialog. There was no concrete way to determine this which is dissapointing, but the debugger let me see where it was failing which was very consistent. Since there is no way in the control to tell it to move its initialization, I disabled it, and have the script to create the client side control in my document load event handler.
This issue is no fault of the control, it was occuring because the content for the popup is actually in a second form. Frankly I'm surprised it ever worked.
Do you have any javascript that is manipulating the DOM, as the case is described at http://support.microsoft.com/kb/927917#more_information ?
Try moving all script blocks to the very bottom of the page, just before the </body> tag, and don't try to set the innerHTML property of the body tag itself.
If the problem is with javascript executing before the DOM is fully built, try moving any initialization calls into a function that will run only after the page is fully loaded. So, instead of something like this:
<div class="myWidgetControl"/>
<script type="text/javascript">
initializeWidgets();
</script>
Try something like this:
<div class="myWidgetControl"/>
<script type="text/javascript">
$(document).ready(
function () { initializeWidgets(); }
);
</script>
You can use script provided by IE Blog to investigate the problem. See: http://blogs.msdn.com/ie/archive/2009/09/03/preventing-operation-aborted-scenarios.aspx
This is a nifty trick I used (based on the link in the JS comments below) that completely avoids the Op Ab error without affecting performance in other browsers. You first wrap whatever script you're doing that can cause the error (for instance, loading/instantiating a 3rd-party widget) in a function, then call that function within the delayExecutionForIE function -- note that the call to myFunction is in there twice, once for IE and once for nice browsers.
Your 3rd-party script might prevent this working, depending on exactly what it does and how it expects to be loaded, but it's definitely worth a try.
function delayExecutionForIE() {
if ( typeof document.all == "object" &&
(document.readyState != "loaded"
&& document.readyState != "complete")
) {
try {
//If IE is used, use the trick by Diego Perini
//http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
myFunction();
} catch(error) {
setTimeout(delayExecutionForIE, 200);
}
} else {
myFunction();
}
}
function myFunction() {
//this is your function that manipulates the DOM
}
delayExecutionForIE();
in the most cases it is a DOM issue in JS.
$( element ).append( someHtml );
so in IE you can add content to a object only if it has it's closing tag
For example the code below will cause the IE7 to bring the message "Operation aborted"
<div id="o">
...
$(o).appendChild();
...
</div>
And the right way
<div id="o">
...
</div>
$(o).appendChild();
Although IE8 will no longer cause that error to "crash" the rendering entirely, instead logging an error, it is unfortunately not caught by the JavaScript debugger found in the new Developer Tools, and the error message doesn't tell you where the error really occurred.
A workaround, which is certainly tedious, but could locate the issue, is to use IE8's debugger to put a breakpoint on the very first piece of JavaScript code that is run, and then continue hitting the "Step" button until the error icon pops up in the bottom left corner of the browser. When that happens, you know the line of code that causes the error was the one highlighted just before you clicked step. It's likely to be quite a bit of code you'll be stepping through, though, but I can't think of anything else (well, except contacting the vendors of that 3rd party code and seeing if they have any updates that might be related).
Of course, you could just tell your users to upgrade to IE8. ;)
And Microsoft does recommend upgrading to IE8!

Categories