3

Possible Duplicate:
javascript object max size limit at 10000 chars

I want to check whether html source contains a specified string, but I'm only getting 10,000 characters (in alert box)

var str=document.documentElement.innerHTML;
if(str.indexOf("abcxyz") !== -1)
{
  alert(str);
}

How can I fix that?

Community
  • 1
  • 1
Cindy
  • 105
  • 1
  • 6
  • 5
    It is probably a character limit on your browser's `alert()` (that isn't what your code above does though) – Michael Berkowski Nov 24 '12 at 00:08
  • 1
    Possible duplicate? http://stackoverflow.com/q/5927647/337315 – CodeLikeBeaker Nov 24 '12 at 00:10
  • 2
    Please 1) ask a single question 2) post code that actually reflects the problem. –  Nov 24 '12 at 00:15
  • @pst I'll remember it next time. Thank you all for your help! – Cindy Nov 24 '12 at 01:33
  • I know everyone is all eager about closing questions, but the problem here is that even though the linked question does address the question here, the subject title is so different that even a reasonable search effort won't be too likely to turn up that question. That means that the typical user experience to find an answer to this question, then have to go to the linked issue. That gives a poorer user experience. – Itsme2003 Dec 31 '16 at 01:19

1 Answers1

2

If you need to display a huge string in alert boxes, I guess you could split it into 10,000-character chunks and display them in order. Alternatively, just use console.log to print it out.

And is there a better way to detect a "onClick" event?

Better than what? JavaScript events will bubble up to the top containing element (unless some element in the chain calls stopPropagation()), so an easy way to detect click events would be to attach a click handler to document.body:

document.body.onclick = function() { alert('Click!'); }
Mihai
  • 2,835
  • 2
  • 28
  • 36