Forum Moderators: open

Message Too Old, No Replies

Whats wrong on this replace

Should only replace linefeeds by <br><br>

         

jetteroheller

11:09 am on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



<script>

function event_window(from_field)
{
var event=window.open('','event','width=300,height=300,scrollbars=1');
var content=document.getElementById(from_field).innerHTML;
content=content.replace('\\\\n','<br><br>');
var html='<html><body>'+content+'</body></html>';
event.document.open();
event.document.write(html);
event.document.close();
}

</script>

<div id=event_from_521 onClick=event_window('event_from_521')>Here goes a very long text, but here by style=hieght:30;overflos:hidden only the first 2 lines visible
</div>

On the main document is with overflow:hidden the first 2 lines of the event.

Clicking on the field, a new window should open (this works fine)

And each linefeed should be replaced by <br><br> to have it better formated.

No idea, why the replace does not work.

It's for my new Andoid cell phone, to carry a part of my database always with me.

daveVk

11:38 am on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try setting CSS line-height instead, new lines characters in html do not result in new lines in page layout (in most cases).

jetteroheller

6:02 pm on Jan 7, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Try setting CSS line-height instead, new lines characters in html do not result in new lines in page layout (in most cases).

Out of this reason, for the display in the pop up window,
the new line characters should be replaced by <br>

daveVk

1:33 am on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



content=content.replace(/\n/g,'<br>');

should do what you ask, if it achieves the desired result is another issue.

The regular expression /\n/g is needed to replace more than the first.

jetteroheller

5:51 am on Jan 8, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks! It works!