Forum Moderators: open
If so, what should the code look like?
Thanks
Anni
[edited by: tedster at 9:10 pm (utc) on July 6, 2002]
[edit reason] changed java to javascript - very different things! [/edit]
Also, it's best to use the type attribute - the language attribute is going to be leaving us. You can use both, to keep old browsers happy:
<script language="JavaScript" type="text/javascript">
document.write('<a href="http:\/\/www.mysite.com">My site<\/a>')
</script>
Anni
document.write('My site'.link('http://www.mysite.com'));
That seems like a long way around the problem, but if you have stored the links and texts in variables, it makes it easier to automate the process. So, instead of, for example:
document.write('<a href="'+hyperLink[i].url+'">'+hyperLink[i].text+'</a>');
you can write:
document.write(hyperLink[i].text.link(hyperLink[i].url));
You could probably make the code even easier with the with statement, though this is discouraged:
with(hyperLink[i]) document.write(text.link(url));
The obvious drawback is that you can't add any extra attributes, such as title or class.
(Yeah, I'm always on the lookout for ways to cut down on the amount of code I write.)
I'm sorry to be so green....
I would love to cut the code down on my pages... One thing I would love to be able to do is to put one line of code in a page or css file that would have the same effect as putting
onMouseOver='window.status=" ";return true' onMouseOut='window.status="Done";return true'
on all my affiliate links! I can't find a way of doing it though which is a real shame. I guess I just need something that would disable the status bar for all mouseover actions....
Hey ho...
Anni
OK, but that's only the case when using regular expressions. Are there browsers that will have problems with this even when using normal strings "" or ''?
*I just found a top-tip that'll help me remember this which I'd never thought of before: A forward slash is leaning forward and a back slash is leaning backwards (if you read left-right anyway;)).
for(var i=0; i<document.links.length; i++){
document.links[i].onmouseover='status=""; return true;';
document.links[i].onmouseout='status="";';
}
You'd need to call it after the document has loaded -- I think.
(Don't use status="Done" -- it's not helpful. Besides, I have a German OS, so mine doesn't say "Done" when a page has finished loading, it says "Fertig".)
For storing links in variables -- well, it probably depends on stuff like how many times on one page the links are to appear. Twice, and it might be worth it. Once, and... you'll have to weigh up the pros and cons.
Here's one suggestion (again, untested):
var linkArr='myfirstsite.com=My first site*mysecondsite.com=My second site*mythirdsite.com=My third site'.split('*');
var hyperLink=new Array();
for(var i=0; i<linkArr.length; i++){
hyperLink[i]=new Object;
var linkPair=linkArr[i].split('=');
hyperLink[i].url='http://www.'+linkPair[0];
hyperLink[i].text=linkPair[1];
}
You should end up with an array called hyperLink, each element being an object with two properties: url is the URL of the link (its destination), and text is the text for the link. The first line contains the link URLs and the link texts -- each pair is separated by an asterisk, within each pair the URL and text is separated by an = sign. You can use whatever symbols you want, as long as you remember to edit the relevant split() statements.
Note that I have cut corners by adding "http://www." to the beginning of each URL within the loop. That will only work, of course, if all of your URLs begin with [www....] -- which they may not.
Thanks,
but I found I can do this <BODY onmouseover="window.status=' ';return true;">
and it cuts out all my excess code with one line.
I do want to disable the status bar, as it enables me to hide affiliate codes. Surfers are getting quite savvy and some will use the status bar to see the link and then type in just the domain minus the all important affiliate ID.
Of course if they really want they can still view source, but hey if they're going to go that far to avoid clicking a link, good luck to them.
Tchuss (spelling) Ich spreche nur ein bissien Dutche (Englander)
I don't say that this is fool proof, it just works for me, I have tested with and without doing this and I get an increase of about 5% in sales when I use it. Its each to his own of course.
Anni