Javascript is freezing the browser when running this code
Posted
by
user1420493
on Stack Overflow
See other posts from Stack Overflow
or by user1420493
Published on 2012-10-26T22:44:10Z
Indexed on
2012/10/26
23:00 UTC
Read the original article
Hit count: 136
JavaScript
|hyperlink
I am trying to get the value of a text input and check if there is any links in it and then take those links and make them into tags. But when I run this code, something is going wrong and it completely freezes the page. Basically, I want it to check for "http://" and if that exists, to keep on adding to the substr length until the end of the string/link. Is there a better way to do this?
// the id "post" could possibly say: "Hey, check this out! http://facebook.com"
// I'd like it to just get that link and that's all I need help with, just to get the
// value of that entire string/link.
var x = document.getElementById("post");
var m = x.value.indexOf("http://");
var a = 0;
var q = m;
if (m != -1) {
while (x.value.substr(q, 1) != " ") {
var h = x.value.substr(m, a);
q++;
}
}
© Stack Overflow or respective owner