Javascript error in IE - javascript

I have a page which is showing a javascript error in IE, stating which line the error is on, but the there are so many linked files I have no idea which line of code it is referring to.
Is there a way to find out which line / linked file it is relating to?? I'm sure I could fix the problem if I knew where it was.
Here is the error message from IE...
Message: 'null' is null or not an object
Line: 2231
Char: 5
Code: 0
URI: http://www.hpbtenancies.co.uk/location/JF/default.aspx

It happens on the line the error reports.. 2231 on default.aspx
dd.onchange = function(){ link.href = hrefOrig + dd.value;
The detailed error is
dd is null
Use Firefox which has better reporting and also use FireBug for even more flexibility in debugging javascript..
IE 8+ also has improved javascript debugging tools. In the console you will see
SCRIPT5007: Unable to set value of the property 'onchange': object is null or undefined
default.aspx, line 2231 character 5

Right-click on the page with the error, click 'View source', scroll down until you reach line 2231 - that's where your error is.

Related

How to catch all javascript warnings and errors to an output div?

i'm using try, catch, for debugging, but warnings is not create exceptions. How to get all javascript warnings and errors to output div?
UPDATED:
If browser supports Afaik logging, how to get that log to string or output div?
UPDATED:
I found the way how to do that:
i can reload console.log function to my custom function an call native console.log function.
First of all, get rid of the try catch. Don't use try catch when you are debugging.
Second, you don't want to out errors to a div, use firebug or inspector for that - console.log();
Third, if you really want to do it: you could use try catch and in the catch, use something like
$('body').append($('div').html('variable for error message goes here'));
if you are using jquery
OR
document.getElementByTagName("body").appendChild( document.createTextNode("variable for error message goes here") );
if you have plain javascript
EDIT: try looking up ie debug bar , ie webDeveloper
I understand myself why someone may want something to actually happen when an error occours in the document. The answers above just say that you would use developer tools, but I needed things to actually happen, and after some searching, here's what I found...
If you wish to catch all errors that come through, you can put the following code into your file, best at the top:
window.onerror = function(errorMsg, url, lineNumber){
// any action you want goes here
// errorMsg is the error message itself.
// url should be the file presenting the error, though i have
// found that it only presents to me the address of the site.
// lineNumber is the line number the error occoured on.
// here is an example of what you could do with it:
alert("Error in " + url + " at " + lineNumber + ":\n" + errorMsg);
}
I, myself, like to output the errors to a div that contains them all, though you can do literally anything to this information that you could do with any other string passed to a function.
Here is an example of what may happen if you throw an error with a button using the code above:
Error in your.site.here at 1:
Uncaught ReferenceError: foo is not defined
For IE javascript debugging you can follow this guide:
http://msdn.microsoft.com/en-au/library/ie/gg699336(v=vs.85).aspx
Keep in mind that the developer tools window must be open prior to loading the page for the warnings and errors to appear in the console.
For webkit, (chrome, safari) developer console - here is a guide:
https://developers.google.com/chrome-developer-tools/docs/console
...Firefox also has a console

error appears out of blue in console

I am receiving an error in my error console which states: arguments array passed to Function.prototype.apply is too large and the file it is in is: resource://ct2504091/BackStage.jsm. Does anyone know why this error suddenly appears out of the complete blue?
Below is the code from the view source of where the error is appearing in:
var postBytes = stream.readByteArray(stream.available());
poststr = String.fromCharCode.apply(null, postBytes);
A Google search for "javascript BackStage.jsm" reveals: You seem to have installed a "Bibirmer for Firefox Plugin" that interfers with you code. Try uninstalling it.

iPad JavaScript Error not helpful

I get the following error and iPad but not in desktop browsers:
JavaScript: Error
undefined
TypeError: 'undefined' is not a function
This is a larger js application, and this error message is totally unhelpful. Is there any way I can get the line number of the error or anymore information?
Update: This just got funky.
line : 0
page : undefined
desc : TypeError: 'undefined' is not a function
chr : undefined
Did the user agent spoofing in FF and safari. No error.
You could try registering a custom error handler to window.onerror
window.onerror = function (desc,page,line,chr)
{ alert('Line:'+line); }
desc = Error message
page = File/Page where the error occured
line = Well...
chr = Character position of the error in the line
If you bind an error handler to window.onerror, it should give you the line number, e.g.
window.onerror = function(msg,url,line) {
alert('The error is on line '+line);
}
This question: Debug JavaScript errors on iPad seems to indicate you can enable debugging too.
If the script is loaded dynamically, though, it can be hard to get such info in any environment.

Why is a button submitting a form even when I set the type to button (rather than submit)?

Click on "Add another start and end time." Notice that the "Remove this segments." buttons are behaving as if their types are not being changed. I ran this through JSLint without any issues and I'm not getting errors in the console. Using the web developer tools in Chrome, it looks like it's type attribute isn't getting set. I can't figure out what's going on.
http://jsfiddle.net/gtr053/xtGPR/
Firefox says:
Error: uncaught exception: [Exception... "Index or size is negative or greater than the allowed amount" code: "1" nsresult: "0x80530001 (NS_ERROR_DOM_INDEX_SIZE_ERR)" location: "http://fiddle.jshell.net/gtr053/xtGPR/show/ Line: 39"]
Line 39 is:
document.getElementById('start_end_times').getElementsByTagName('tbody')[0].deleteRow(index);
So presumably index is wrong.

Javascript error only in IE8

I get this javascript error in IE 8
SCRIPT5007: Object expected
The error point to this line
/*#cc_on(function(a,b){function r(a){var b=-1;while(++b<f)a.createElement(e[b])}if(!window.attachEvent||!b.createStyleSheet||!function(){var a=document.createElement("div");return a.innerHTML="<elem></elem>",a.childNodes.length!==1}())return;a.iepp=a.iepp||{};var c=a.iepp,d=c.html5elements||"abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|subline|summary|time|video",e=d.split("|"),f=e.length,g=new RegExp("(^|\\s)("+d+")","gi"),h=new RegExp("<(/*)("+d+")","gi"),i=/^\s*[\{\}]\s*$/,j=new RegExp("(^|[^\\n]*?\\s)("+d+")([^\\n]*)({[\\n\\w\\W]*?})","gi"),k=b.createDocumentFragment(),l=b.documentElement,m=b.getElementsByTagName("script")[0].parentNode,n=b.createElement("body"),o=b.createElement("style"),p=/print|all/,q;c.getCSS=function(a,b){try{if(a+""===undefined)return""}catch(d){return""}var e=-1,f=a.length,g,h=[];while(++e<f){g=a[e];if(g.disabled)continue;b=g.media||b,p.test(b)&&h.push(c.getCSS(g.imports,b),g.cssText),b="all"}return h.join("")},c.parseCSS=function(a){var b=[],c;while((c=j.exec(a))!=null)b.push(((i.exec(c[1])?"\n":c[1])+c[2]+c[3]).replace(g,"$1.iepp-$2")+c[4]);return b.join("\n")},c.writeHTML=function(){var a=-1;q=q||b.body;while(++a<f){var c=b.getElementsByTagName(e[a]),d=c.length,g=-1;while(++g<d)c[g].className.indexOf("iepp-")<0&&(c[g].className+=" iepp-"+e[a])}k.appendChild(q),l.appendChild(n),n.className=q.className,n.id=q.id,n.innerHTML=q.innerHTML.replace(h,"<$1font")},c._beforePrint=function(){if(c.disablePP)return;o.styleSheet.cssText=c.parseCSS(c.getCSS(b.styleSheets,"all")),c.writeHTML()},c.restoreHTML=function(){if(c.disablePP)return;n.swapNode(q)},c._afterPrint=function(){c.restoreHTML(),o.styleSheet.cssText=""},r(b),r(k);if(c.disablePP)return;m.insertBefore(o,m.firstChild),o.media="print",o.className="iepp-printshim",a.attachEvent("onbeforeprint",c._beforePrint),a.attachEvent("onafterprint",c._afterPrint)})(this,document)#*/
However all that had been commented. Some ajax calls aren't being executed(again only in ie). Is it because of this error or something else? Thanks
/*#cc_on is IE's very own conditional comment - it is executed in IE and ignored in other browsers. If you cannot find uncompressed version of script, you can yust insert line breaks to narrow problematic code.

Categories

Resources