Uncaught TypeError ONLY in Chrome - javascript

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...

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();
});

Sporadic JS Bug Chasing: Too Much Recursion

I am hesitant to ask yet another "too much recursion" question, but I'm totally lost for ideas.
I am getting a "too much recursion" error during my .ready(), which is unhelpfully occurring:
Very sporadically (ie once a month) for me
Pretty much every other time I have to do a demo using someone else's computer (of course)
On FF, Chrome, IE9 etc, on our dev, prod and test systems
And it's getting trapped deep inside the bowels of jQuery (1.10.2). Specifically, at this line of Sizzle, inside Sizzle.attr.
I've tried to "force" this bug to appear by using low memory VMs, but that doesn't seem to help. I'm stumped as to how to find where this is occurring, since I can't get a stack trace. I've got no minimal example either, since I can't make the bug happen.
The most likely candidate is something like triggering an event inside its handler, but I can't see how that would occur only sometimes, on load?
How can I try and find what is happening?
Any help or tips or links most welcome. If it's useful, I'm using jQuery, jQuery UI, and OpenLayers.
Try looking at a JS stacktrace when it errors to see the call chain - for a recursion problem this should show you what's recursing. You can see this with dev tools in the browser, for example in Firefox use Firebug's 'script' tab and use the 'stack' output tab.
Just noticed you'd said you'd tried to get a stack trace. Try putting a breakpoint at the line you know is bad and looking at the stacktrace to see if/when it seems to be recursing into some function above that line.

Javascript firefox issue

I developed a .htm document with an in-built script for javascript to run a program. In google chrome, the program works fine, but I got a beta test complaint that it didn't work on firefox 14.01 or opera. On testing with firefox 14.01, I can confirm it doesn't work (I assumed opera to be the same). I cannot insist the audience upgrade their browsers, as this is supposed to be widely compatible.
Doing a little tracing of the issue, I installed Firebug, which, on clicking the Javascript button to generate a coordinate the first time, it worked (clearly showing the function is defined and exists), but the second time, Firebug complained that:
"ReferenceError: GenerateCoord is not defined".
This wouldn't be so ironic if it only did this after generating an (encrypted) coordinate (thus calling GenerateCoord that is supposedly 'undefined').
If one looks in the code, one can clearly see that the function GenerateCoord is clearly defined before it is called. I would say firefox has an 'onclick' issue, but then it begs the question why did it work the first time I clicked it (calling GenerateCoord via 'onclick') but not the second?
Reloading the file allows the button to work the first time, and the first time only. I am baffled as to how firefox can call a function one time that it then says is undefined the next. Am I missing something here?
Javascript and HTML code can be viewed here:
http://pastebin.com/4qykTfEW
-
How do I solve the problem, and is there an easier solution than re-writing the code to avoid onclick (that seems to work in certain circumstances but not others)?
The problem is that using document.write overwrites the entire HTML page, thus inadvertently removing the GenerateCoord script. I'd suggest appending the link to the document (in ShowTarget) rather than attempting to re-write it.
For example, have a container element where the link should be:
<div id="links_container"></div>
Then to append the links, use:
document.getElementById('links_container').innerHTML = Link;

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.

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.

Categories