Calling a function in an iFrame in IE9 - javascript

I have a problem that is specific to IE9.
We are using Autodesk MapGuide which has a framework of several nested Framesets. I am trying to call a Javascript function that sits within an IFrame that is within the top level frameset. (Please I dont want to discuss the merits or otherwise of framestes here.)
I have adapted some code I found in another thread using Jquery
window.top.$("#MyIframe")[0].contentWindow.MyFunction();
This works perfectly in IE7 and IE8, but as soon as I try it in IE9 I get the following error:
TypeError: Unable to get value of the property 'contentWindow': object
is null or undefined
I suspect that it is struggling with the framesets and can't find '#MyIframe'.
Is there some other format I can try to get around this? Many thanks in advance for your help.

Related

Removing HTML element in iframe with JavaScript

I'm attempting to remove an image from an embedded iframe (inline iframe). While it works sometimes, sometimes it failes with an error. I am running this code on Chrome. This behaviour is strange. I have tried this on a few sites and I am unable to find any reason for this.
I would like to know why it fails sometimes and does not sometimes with all parameters the same (I'm simply executing this in the console). Secondly, if possible is there an alternative solution?
$("#content_ifr").contents().find("img").remove();
Error message that occurs sometimes:
Uncaught TypeError: Cannot read property 'contents' of null
If it helps, I'm attempting to remove images and extra content from the WordPress page editor (Classic) using JavaScript.
Being that you said it sometimes works and sometimes it doesn't. When it works, check the Javascript context. I was running into issues where my code worked with DevTools opened, but if I refreshed the page, the javascript context would revert to "Top", and I needed to be in that frame.
[
Turns out that my Chrome extension was interfering with this. We were attempting to run this script using a Chrome extension on a WordPress site.
Changing these lines to this worked:
jQuery("#content_ifr").contents().find("img").remove();
As #Jason Owens pointed out, the context was for some reason switching. I noticed that using 'jQuery' instead of $ seemed to work. I think this was because the Chrome extension was using standard jQuery as a dependency. However, '$' didn't work WordPress avoids the '$' symbol using noConflict and uses 'jQuery' instead.
We can't remove elements from Iframe but we can hide
Try This:
$(document).ready(function(){
$('#content_ifr').contents().find('img').hide();
});

Uncaught TypeError ONLY in Chrome

I#ve a very strange problem calling a simple function in JavaScript.
Just for example, even a simple:
click
or:
click
gives me an Uncaught TypeError: object is not a function.
But ONLY in Chrome and ONLY on my Notebook. On my Workstation (same system, exactly same Chrome Version) and in every single other browser this line works as expected.
Im Working with JS since a few years, but this error drives me nuts since days.
The Website comes with scriptaculous and some handwritten JS, but nothing really special.
scriptaculous works well, JS-Console shows no errors except the one #Chrome on my Notebook.
Anyone of you ever had this before?
I#ve really no idea whats going on.
My suggestion is to assign it via javascript and not like an inline attribute. Sometimes you get odd behaviour setting it as an attribute.
You could use jQuery:
jQuery('.myClickableLink').click(function(){ alert(123) })
I think that's a simpler way.
I am betting you have a pop up blocker installed on that machine that hijacks window.alert. Disable the plugins and see if it works correctly. [Normally a pop up blocker does this]
use
window.alert('msg)';
it will work...

What's the general solution to "typeerror object doesn't support this property or method" on IE8?

I saw several specific questions about this problem - getting typeerror object doesn't support this property or method in IE8, each with its specific answer.
Suppose I have a large website with lots of code ... I don't know what specific snippet is causing this error.
Is there a general method to debug this? I've tried with the IE Developer Tools, and it doesn't break on error. Is this caused by incorrect javascript syntax? Should I try something like js lint?
What's the correct, general way to identify and deal with this problem?
OK, so I turned to the age old solution and started to delete massive chunks of code from my project until the problem was "fixed". This helped me locate the problematic file.
I then proceeded to delete function by function until I found this little snippet: str.trim(). A quick search turned this up.
Update: Actually, I just realized something ... the problem was just a normal exception, and passing it to alert() masked the details. If you let such exceptions go to the top, then whatever browser you use will display useful line information. So, the next time it happens to me, I'm going to look for a way to make the exceptions fly high outside of the top level function. The catch wasn't in my code, it was jQuery, so I'm still not quite sure how to do it.

Appending an element created as an object property

I have a script which appends a newly-created div to the body element onload. I need to keep a reference to that div throughout the application, so I store it in my main global object.
var oMyObj = {};
window.onload = function () {
oMyObj.eDiv = document.createElement("div");
document.getElementsByTagName("body")[0].appendChild(oMyObj.eDiv);
};
Nothing particularly ground-breaking, I'm sure you'll agree. Anyway, it worked absolutely fine until I started testing in IE9. All of a sudden I get an error message saying "オブジェクトの呼び出しが無効です" (I'm currently working in Japan), which sort of translates to "the object call was null/invalid". Not sure what the precise English version of the error message is.
Anyway, I searched and found (http://d.hatena.ne.jp/wang-zhi/20110503/1304361114 - sorry, also in Japanese) that it was due to the RealPlayer DivX plugin. After disabling the plugin, it worked fine. It also works fine if I use a meta tag to force IE9 to run as IE7. So it is not a major problem. But I would like to know if there is a "correct" way to do what I am trying to do so that it will work in IE9 as IE9. I can only assume that what I am doing now is not what I'm supposed to be doing.
Any ideas?
Okay, well I have confirmation that it was the DivX (not RealPlayer; no idea why I mixed them up) Plugin causing the problem. The plugin overwrites some of the core DOM functionality, including appendChild, which seems insane to me, but whatever. DivX acknowledged the bug and are apparently going to fix it in the next update. Yay, I guess.

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.

Categories