By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,032 Members | 825 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,032 IT Pros & Developers. It's quick & easy.

Split Text Line Function (fix for firefox word wrapping issue)

P: 3
I've been searching for a while now for a solution to the firefox word wrapping issue.

I found a solution here @

http://javascript.about.com/library/blspline.htm

I followed the instructions exactly but I cannot get it to work. I am not a programmer and I am just wondering if this function is broken? I tried everything I can think of with document.write

I can't get any text to output or sometimes I get "undefined" as an output.

I've also tried like it says in the example:

<SCRIPT LANGUAGE="JavaScript">
var myText40 = splitLine(myText,40);
var myHTML = myText40.replace(/\n/g,'<br \/>');
</script>

But it nothing outputs. Can anyone help this newb here? Thanks in advanced hehe



<SCRIPT LANGUAGE="JavaScript">

// Line Splitter Function
// copyright Stephen Chapman, 19th April 2006
// you may copy this code but please keep the copyright notice as well

<!-- Begin
function splitLine(st,n) {
var b = '';
var s = st;
while (s.length > n) {var c = s.substring(0,n);
var d = c.lastIndexOf(' ');
var e =c.lastIndexOf('\n');
if (e != -1) d = e; if (d == -1) d = n;
b += c.substring(0,d) + '\n';s = s.substring(d+1);
}return b+s;
}

// End -->
</script>
Nov 14 '06 #1
Share this Question
Share on Google+
1 Reply


10K+
P: 13,264
I've been searching for a while now for a solution to the firefox word wrapping issue.

I found a solution here @

http://javascript.about.com/library/blspline.htm

I followed the instructions exactly but I cannot get it to work. I am not a programmer and I am just wondering if this function is broken? I tried everything I can think of with document.write

I can't get any text to output or sometimes I get "undefined" as an output.

I've also tried like it says in the example:

<SCRIPT LANGUAGE="JavaScript">
var myText40 = splitLine(myText,40);
var myHTML = myText40.replace(/\n/g,'<br \/>');
</script>

But it nothing outputs. Can anyone help this newb here? Thanks in advanced hehe



<SCRIPT LANGUAGE="JavaScript">

// Line Splitter Function
// copyright Stephen Chapman, 19th April 2006
// you may copy this code but please keep the copyright notice as well

<!-- Begin
function splitLine(st,n) {
var b = '';
var s = st;
while (s.length > n) {var c = s.substring(0,n);
var d = c.lastIndexOf(' ');
var e =c.lastIndexOf('\n');
if (e != -1) d = e; if (d == -1) d = n;
b += c.substring(0,d) + '\n';s = s.substring(d+1);
}return b+s;
}

// End -->
</script>
Javascript forum please
Nov 14 '06 #2

Post your reply

Sign in to post your reply or Sign up for a free account.