PDA

View Full Version : It is possible to add 2 random iframe in one single page?



jamewoong
03-19-2005, 09:46 PM
Hi,

Is there any professional about javascript here? I would like to know if it's possible to load two random iframe in one single page.

I'm using this as the random iframe:

<script language="JavaScript1.2">

//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=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'

//Specify random URLs to display inside iframe
var randomcontent=new Array()
randomcontent[0]="random1.htm"
randomcontent[1]="random2.htm"
randomcontent[2]="random3.htm"
randomcontent[3]="random4.htm"

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

</script>


It is possible to add 2 random script in one single page?

Thanks.

jscheuer1
03-19-2005, 11:22 PM
You should check out this thread, the modifications and subsequent positioning issues that may arise are almost identical:

Need help configuring 3 DD scripts on same page - Daily IFrame Content (http://www.dynamicdrive.com/forums/showthread.php?t=2047)

Once you go through that material, if you still have questions, let me know.

jamewoong
03-22-2005, 12:11 AM
Thanks for the reply.

I tried the whole thing in the page you shown me and it's still not work...

I want to put 2 RANDOM IFRAME at a single page. Following the step shown by jscheuer1, it still doesn't work I don't know why... It only shows 1 random iframe of 2. I want 2 random iframe that show at the same time.

Could you check this for me please?

Please click on the link below and tell what is missing...
http://www.adpaid.info/member/jamewoong

Thanks.

Note:
The content "page to page6" isn't created yet. Just check for me if the script is correct or not.

jscheuer1
03-22-2005, 04:59 AM
That was a mess. Oh well, that's what I get for not giving better instructions. Here is a modified script that should work, and BTW, please leave the credit intact this time:


<script type="text/javascript">

//Random iframe content- Dynamic Drive (www.dynamicdrive.com)
//Modified to produce 2 Random iframes
//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 IFRAMEs display attributes
var iframeprops1='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'
var iframeprops2='width=130 height=130 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="1" scrolling="no"'

//Specify random URLs to display inside 1st iframe
var randomcontent1=new Array()
randomcontent1[0]="random1_1.htm"
randomcontent1[1]="random1_2.htm"
randomcontent1[2]="random1_3.htm"
randomcontent1[3]="random1_4.htm"

//Specify random URLs to display inside 2nd iframe
var randomcontent2=new Array()
randomcontent2[0]="random2_1.htm"
randomcontent2[1]="random2_2.htm"
randomcontent2[2]="random2_3.htm"
randomcontent2[3]="random2_4.htm"

//No need to edit after here
if (ie||dom)
document.write('<iframe id="dynstuff1" src="" '+iframeprops1+'></iframe><br>')
document.write('<iframe id="dynstuff2" src="" '+iframeprops2+'></iframe>')

function random_iframe(){
if (ie||dom){
var iframeobj1=document.getElementById? document.getElementById("dynstuff1") : document.all.dynstuff
iframeobj1.src=randomcontent1[Math.floor(Math.random()*randomcontent1.length)]
var iframeobj2=document.getElementById? document.getElementById("dynstuff2") : document.all.dynstuff
iframeobj2.src=randomcontent2[Math.floor(Math.random()*randomcontent2.length)]
}
}

window.onload=random_iframe

</script>This will produce two random iframes, one after the other vertically. If you need different positioning, let me know.

jamewoong
03-22-2005, 04:04 PM
Thank you very much!!! How come I didn't find the error?

About the credit, I apologize for that. My page was ENCRYPTED, it is why I removed the credit, because it will take space. Also, it's impossible for some to see it.

If you really want me to let the credit intact when the page will be encrypted, so I'll have no choice to respect you and let the credit there...\

Sorry again... :(

jscheuer1
03-22-2005, 04:33 PM
Glad I could help.

About the credit, I'm not affiliated with DD, I just think it is good ethics to include a credit for work freely offered when it is requested. So much so, that I would at least make the effort to include it, not encrypted, in such a case like this. You could easily, after encrypting the page, put this at the very top (right after the !DOCTYPE, if used), before anything else or at the bottom after everything else:


<!-- This page includes:Random iframe content- Dynamic Drive (www.dynamicdrive.com). Modified to produce 2 Random iframes. For full source code, and Terms Of use, visit http://dynamicdrive.com. This credit MUST stay intact for use. -->

That should not mess anything up and be there for the snoopers to see. BTW, if you do use a !DOCTYPE declaration, there is no need to encrypt it.

jamewoong
03-22-2005, 10:27 PM
Hi,

Thanks to comment. I'll add it.

By the way, everyone knows that DynamicDrive.com is the only place to get the BEST javascript...

My first time to get javascript is from here :)