PDA

View Full Version : Open multiple window at once



codex
11-11-2008, 04:33 PM
Hi all, I would like to make a link on my page to open multiple window at once. For example, clicking on the link "Click here" will open 3 new windows at once, each pointing to a different page. I know it is possible to do this with javascript window.open but the page I wanted to open will be dynamic.

In another word, I want a link to open up multiple pages in my rss feed. So the link is not the same each time. May I know how to do this? I would appreciate if you can show me the code =) Thanks in advance

rangana
11-12-2008, 04:37 AM
How are the links being placed? You could contain them in one container and loop through all the links, and assign an onclick event on each of them:


<script type="text/javascript">
var ray={
/**
* links array accepts three params
@ param1 - URL you wish to open
@ param2 - name of the window
@ param3 - window preferences
*/
links:
[
['http://www.google.com','window1','width=300,height=300'],
['http://www.yahoo.com','window2','width=500,height=500,top=100,left=100'],
['http://www.dynamicdrive.com','window3','left=500,width=300,height=300'] // No comma
], // Links you wish to open together with the window name and the preferences
loop:function(el)
{
var lnkArr=this.getID(el).getElementsByTagName('a');
for(var i=0;i<lnkArr.length;i++)
{
lnkArr[i].onclick=function()
{
for(var c=0;c<ray.links.length;c++)
window.open(ray.links[c][0],ray.links[c][1],ray.links[c][2]);
}
}
},
getID:function(el)
{
return document.getElementById(el);
}
}
window.onload=function()
{
ray.loop('contain'); // Pass the ID of the container here
}
</script>
<div id="contain">
<a href="#">Top Anchor</a><br>
<a href="http://www.google.com">http://www.google.com</a><br>
<a href="http://www.yahoo.com">http://www.yahoo.com</a><br>
</div>


Hope that helps.

codex
11-12-2008, 04:58 AM
Thanks. I am aware of that code but the function I am after is not exactly that. I want to open up multiple windows from my rss feed. So I will not know the url for the webpage in advance.

For example: http://news.google.com/?ned=us&topic=t&output=rss

If I wanted to open the latest 3 posts from Google news feed. Is there a way to dynamically assign the feed title and use javascript to open them?