PDA

View Full Version : I am trying to learn javascript



marcorow
06-15-2012, 07:22 PM
I copied a javascript to change pictures onload on a page. I have this script running successfully in many other pages. This time I am trying to use the same script twice in the same page (with different names) but I am not able to figure out what else should I change to make it work. I can get it to work in one place at the time. I believe I need to rename some of the variables but I am not sure which one.
can anybody help me?
here the 2 scripts:
1
pics.js


// JavaScript Document

//Random iframe content- Dynamic Drive (www.dynamicdrive.com)
//For full source code, and Terms Of use, visit http://dynamicdrive.com
//This credit MUST stay intact for use

var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

//Specify IFRAME display attributes
var iframeprops='width="177" height="300" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'

//Specify random URLs to display inside iframe
var randomcontent=new Array()

randomcontent[0]="../frontpagepics/surfer.html"
randomcontent[1]="../frontpagepics/marina.html"
randomcontent[2]="../frontpagepics/ruins.html"
randomcontent[3]="../frontpagepics/flowers.html"
randomcontent[4]="../frontpagepics/lifeguard.html"
randomcontent[5]="../frontpagepics/sailboat.html"
randomcontent[6]="../frontpagepics/palms.html"

if (ie||dom)
document.write('<iframe id="dynpics" src="" '+iframeprops+'></iframe>')

function random_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynpics") : document.all.dynpics
iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
}
}

window.onload=random_iframe

2
advertisement.js


// JavaScript Document

//Random iframe content- Dynamic Drive (www.dynamicdrive.com)
//For full source code, and Terms Of use, visit http://dynamicdrive.com
//This credit MUST stay intact for use

var ie=document.all&&navigator.userAgent.indexOf("Opera")==-1
var dom=document.getElementById&&navigator.userAgent.indexOf("Opera")==-1

//Specify IFRAME display attributes
var iframeprops='width="222" height="320" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"'

//Specify random URLs to display inside iframe
var randomcontent=new Array()

randomcontent[0]="../ads/AdSpace.html"
//randomcontent[0]="../ads/siemens.html"
//randomcontent[1]="../ads/simplyHearing.html"
//randomcontent[2]="../ads/transear.html"
//randomcontent[3]="../ads/westone.html"
//randomcontent[0]="../ads/Vivosonic.html"
//randomcontent[1]="../ads/audigyGroup.html"
//randomcontent[2]="../ads/westone.html"
//randomcontent[2]="../ads/SoundCure.html"
//randomcontent[3]="../ads/audigyGroup.html"
//randomcontent[4]="../ads/transear.html"
//randomcontent[5]="../ads/audigyGroup.html"
//randomcontent[6]="../ads/SilentCall.html"
//randomcontent[6]="../ads/realEar.html"
//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff" src="" '+iframeprops+'></iframe>')

function random_iframe(){
if (ie||dom){
var iframeobj=document.getElementById? document.getElementById("dynstuff") : document.all.dynstuff
iframeobj.src=randomcontent[Math.floor(Math.random()*randomcontent.length)]
}
}

window.onload=random_iframe

vwphillips
06-16-2012, 08:30 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script type="text/javascript">
/*<![CDATA[*/

//Random iframe content- Dynamic Drive (www.dynamicdrive.com)
//For full source code, and Terms Of use, visit http://dynamicdrive.com
//This credit MUST stay intact for use



//Specify random URLs to display inside iframe
var randomcontent=[
"../frontpagepics/surfer.html",
"../frontpagepics/marina.html",
"../frontpagepics/ruins.html",
"../frontpagepics/flowers.html",
"../frontpagepics/lifeguard.html",
"../frontpagepics/sailboat.html",
"../frontpagepics/palms.html"
];

var randomcontent2=[
"../frontpagepics/surfer.html",
"../frontpagepics/marina.html",
"../frontpagepics/ruins.html",
"../frontpagepics/flowers.html",
"../frontpagepics/lifeguard.html",
"../frontpagepics/sailboat.html",
"../frontpagepics/palms.html"
];

function random_iframe(id,ary){
var iframe=document.getElementById(id);
if (iframe){
iframe.src=ary[Math.floor(Math.random()*ary.length)];
}
}

window.onload=function(){
random_iframe('dynpics',randomcontent);
random_iframe('dynpics2',randomcontent2);
}

/*]]>*/
</script>

</head>

<body>
<iframe id="dynpics" src="" width="177" height="300" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
<iframe id="dynpics2" src="" width="177" height="300" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>

</body>

</html>