2 problems

  • Thread starter Palle Christoffersen
  • Start date
P

Palle Christoffersen

Im trying to make a small news bulletin that other website owners can copy
to their websites

But my problem is that im not good at java.

I have 2 problems:

1. how do i make a line break in the
news[1]="bla bla bla";
So it would appear as
bla bla
bla

2. how do i make a link in
document.write(news[1]);
so it would appear
link bla bla bla

The file is called news.js

***********
news=new Array;

news[1]="bla bla bla";
news[2]="blu blu";
news[3]="bly bly";
news[4]="bla blo";
news[5]="blo bla";

function Shownews() {

document.write(news[1]);
document.write(news[2]);
document.write(news[3]);
document.write(news[4]);
document.write(news[5]);

}

**************

This is what i want other website owners to place on their sites.
*************
<script type="text/javascript" src="news.js"></script>
<script type="text/javascript">
Shownews();
*************
 
L

Lee

Palle Christoffersen said:
Im trying to make a small news bulletin that other website owners can copy
to their websites

But my problem is that im not good at java.

This has nothing to do with Java.
Your problem doesn't even have anything to do with Javascript.
These are purely HTML problems:

1. how do i make a line break in the
news[1]="bla bla bla";
So it would appear as
bla bla
bla

2. how do i make a link in
document.write(news[1]);
so it would appear
link bla bla bla

news[1]="<a href='http://www.link.com'>link</a> bla bla bla";
 
I

Ivo

Palle Christoffersen said:
how do i make a link in
document.write(news[1]);
so it would appear
link bla bla bla

news[1]="<a href='http://www.link.com'>link</a> bla bla bla";

I believe that a / in a string needs to be escaped with a \ these days. Like
so:
news[1]="<a href='http:\/\/www.link.com'>link<\/a> bla bla bla";

Another idea the OP might benefit from, is the link method of strings:

news[1] = 'link'.link() + ' bla bla';


What would be the difference when you called ShowNews directly? Put it in
the last line of news.js. I think that would run a lot smoother, with a
highly reduced chance of those others messing things up. In the current
situation, Shownews may be called long before news.js has loaded...
HTH
Ivo
 
L

Lasse Reichstein Nielsen

Ivo said:
I believe that a / in a string needs to be escaped with a \ these days. Like
so:
news[1]="<a href='http:\/\/www.link.com'>link<\/a> bla bla bla";

No. It would need to be escaped inside a Regular Expression literal, and
it needs to be escaped right after a "<" if inside a script tag.
So, the "</\a>" is correct, but the other escapes are not necessary.

/L
 
R

Randy Webb

Lasse said:
I believe that a / in a string needs to be escaped with a \ these days. Like
so:
news[1]="<a href='http:\/\/www.link.com'>link<\/a> bla bla bla";


No. It would need to be escaped inside a Regular Expression literal, and
it needs to be escaped right after a "<" if inside a script tag.
So, the "</\a>" is correct, but the other escapes are not necessary.

Except that <\/a> might work better :)
 
L

Lasse Reichstein Nielsen

Randy Webb said:
Except that <\/a> might work better :)

Obviously. Pah!
/L 'It's late! It's not my fault! I was young and needed the money!'
 
L

Lee

Ivo said:
Palle Christoffersen said:
how do i make a link in
document.write(news[1]);
so it would appear
link bla bla bla

news[1]="<a href='http://www.link.com'>link</a> bla bla bla";

I believe that a / in a string needs to be escaped with a \ these days. Like

I'm not aware of any browser that requires the escape.
I would hope that any published standard would allow
any text at all to appear within quotes.
What have I missed?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top