Re: Dynamic IFRAME problem
- From: Dr John Stockton <jrs@xxxxxxxxxxxxxxxxxx>
- Date: Tue, 21 Feb 2006 15:07:38 +0000
JRS: In article <26543882.BJFIuN1aXx@xxxxxxxxxxxxxx>, dated Mon, 20 Feb
2006 16:45:30 remote, seen in news:comp.lang.javascript, Thomas
'PointedEars' Lahn <PointedEars@xxxxxx> posted :
Furthermore, you should not use consecutive calls of document.write.
No reason here to avoid that. Code should be written to be
comprehensible to its author and maintainers. Any extra time taken by
document.write will here be negligible in comparison with the time taken
in dealing with the http:// references.
However, one should look for ways to reduce repetitiveness in code.
Accumulate the strings to be written instead and write them once, e.g.
var rnd = Math.random(); // still prone to the bug described above, though
var a = [rnd, '<br>'];
if (rnd > 0.5){
a.push('<iframe src="http://www.yahoo.com"><\/iframe>');
}
else
{
a.push('<iframe src="http://www.google.com"><\/iframe>');
}
document.write(a.join(""));
OP : use something like
var rnd = Math.random();
document.write('<iframe src="http://www.' +
(rnd>=0.5?'google':'yahoo') +
'.com"><\/iframe>');
or
document.write('<iframe src="http://www.' +
(Math.random()>=0.5?'google':'yahoo') +
'.com"><\/iframe>');
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
.
- Follow-Ups:
- Re: Dynamic IFRAME problem
- From: Thomas 'PointedEars' Lahn
- Re: Dynamic IFRAME problem
- References:
- Dynamic IFRAME problem
- From: shlomi . schwartz
- Re: Dynamic IFRAME problem
- From: Thomas 'PointedEars' Lahn
- Dynamic IFRAME problem
- Prev by Date: Re: Setting focus AND anchors
- Next by Date: Re: uploading directories recursively
- Previous by thread: Re: Dynamic IFRAME problem
- Next by thread: Re: Dynamic IFRAME problem
- Index(es):
Relevant Pages
|