Re: Dynamic IFRAME problem



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.
.



Relevant Pages

  • Re: IS the Hobbyist program active, I cant get any results
    ... email service. ... see why he should have to put in the extra time and effort to fix ... I have no reason to believe they ... don't sell your personal information and second, ...
    (comp.os.vms)
  • Re: Clarifying coldness and harsh hangovers?
    ... if that's the reason. ... That's why expensive booze is expensive- the distiller takes extra time ... the extra care, they get it "good enough" to meet the regs and it's done. ...
    (rec.crafts.meadmaking)
  • Re: change (domain) password on WinXP problem ...
    ... >extra time on the day the password should be changed for the system to prompt ... is there any reason for this, ... >configuration problem in XP that needs to be specifically addressed? ...
    (microsoft.public.windowsxp.general)
  • Re: rsync copying files it doesnt need to
    ... Les Mikesell wrote: ... owner/group/permissions. ... Perhaps there is some reason it can't. ... In any case it probably doesn't take much extra time for this step. ...
    (Fedora)
  • Re: Comparing COUNTs from a self-join
    ... and it will take a second or so to DELETE the previous data in the two temp ... I'd like to avoid that overhead and extra time, ...
    (microsoft.public.sqlserver.programming)