Click to See Complete Forum and Search --> : passing parameters problem
swapnil_paranjape
July 25th, 2005, 03:51 AM
hi
i am trying to send the parameters to the popup window from js function.
Now this is my js function and i am trying to send parameters to popup.
var newwindow = '';
function popitup(url,st,ed)
{
newwindow=window.open(url,'name','height=400,width=350');
var txt = st+'<br>'+ed
newwindow.document.body.innerHTML += txt;
}
this is the call to the function
popitup("\main.html","10","20");
This is javascript in my popup window(html) page
var begin = ' ';
var end = ' ';
document.write(begin)
document.write("<br>")
document.write(end)
document.write("<br>")
but this is not working......
whats the problem?how should i send the parameters?i want to write that paaramets in popup window.
olivthill
July 25th, 2005, 05:38 AM
A little remark: quotes have been forgotten in 'height=400','width=350'. But even without the quotes, it is working well for me with the following lines:
<html>
<head>
<script language=javascript>
var newwindow = '';
function popitup(url,st,ed)
{
newwindow=window.open(url,'name','height=400','width=350');
var txt = st+'<br>'+ed
newwindow.document.body.innerHTML += txt;
}
</script>
</head>
<body">
<a href="javascript:popitup('popupwindow1.htm','10','20');">Click here and a window will pop up</a>
</body>
</html>
and popupwindow1.htm contains
<html>
<head>
</head>
<body>
<h1>Hi, I am a pop up window</h1>
<script language=javascript>
var begin = ' ';
var end = ' ';
document.write(begin)
document.write("<br>")
document.write(end)
document.write("<br>")
</script>
</body>
</html>
I suppose that the problem is
olivthill
July 25th, 2005, 06:37 AM
Another solution is:
<html>
<head>
<script language=javascript>
var newwindow = '';
function popitup(url,st,ed)
{
newwindow=window.open(url,'name','height=400','width=350');
newwindow.document.getElementById('text1').innerHTML += st;
newwindow.document.getElementById('text2').innerHTML += ed;
}
</script>
</head>
<body">
<a href="javascript:popitup('popupwindow1.htm','10','20');">Click here and a window will pop up</a>
</body>
</html>
and
popupwindow1.htm contains:
<html>
<head>
</head>
<body>
<h1>Hi, I am a pop up window</h1>
<script language=javascript>
document.write("<span id='text1'>start:</span>")
document.write("<br>")
document.write("<span id='text2'>end:</span>")
document.write("<br>")
</script>
</body>
</html>
swapnil_paranjape
July 25th, 2005, 06:45 AM
i got the solution for my above problem...now this is new question i want to ask regarding the above problem ......
i have this function
var newwindow = '';
function popitup(url,st,ed)
{
newwindow=window.open(url,'name','height=400,width=350');
var txt = st+'<br>'+ed
newwindow.document.getElementsByTagName('body')[0].innerHTML=txt;
}
AND THE CODE WRITTEN IN THE BODY IS
alert("Click OK ");
popitup("\trial.html","10","20");
alert("click ok alert2");
popitup("\trial.html","30","40");
now here 10 20 first gets displayed in popup window and then 30 40 gets diaplayed in popup window overwriting the 10 20
but i want to display both outputs in one window one below other...
how can i do this?
infact whenever i make a call to this function the o/p should get appened to previous o/p in the popup window
please help me.
swapnil_paranjape
July 26th, 2005, 12:31 AM
I am using this code.....and checking weather the window is open or not and trying to append the o/p but still i am not getting o/p as expected....
this is my function
var newwindow = '';
var txt ='';
function popitup(url,st,ed)
{
if (!newwindow.closed && newwindow.location)
{
newwindow.location.href = url;
}
else
{
newwindow=window.open(url,'name','height=400,width=400');
if (!newwindow.opener) newwindow.opener = self;
}
if (window.focus) {newwindow.focus()}
txt= st+'<br>'+ed
newwindow.document.getElementsByTagName('body')[0].innerHTML=txt;
}
still if i make consecutive function call like this ...
popitup(url,10,20)
popitup(url,30,40)
the output is :
first 10 20 gets displayed and then 30 40 is displayed in the same window overwriting 10 20.....i dont want that...i want 10 20 followed by 30 40.
how to do that?please help me....
thank you
sphereis
August 2nd, 2005, 11:06 PM
there are several ways to do this. an easy (and untidy) way is to store what is supposed to be stored in innerHTML in global var.
e.g.
var txt1="";
var txt2="";
function popitup(url,st,ed)
{
//blah blah blah
txt1+= " "+st;
txt2+= " "+ed;
newwindow.document.getElementById('text1').innerHTML = txt1;
newwindow.document.getElementById('text2').innerHTML = txt2;
}
hope this helps.
reminder: do note that innerHTML is IE specific. You need to modify things here and there for it to work in other browsers. My advice is to use W3CDOM and use the [object].appendChild method.
another possible improvement is to store the data as 2 arrays instead of strings so that you can iterate and process them later if necessary. You can write a specialized function to format an array into a string for display purposes. A quick and dirty example is as follows:
var array1 = new Array;
var array2 = new Array;
function popitup(url,st,ed)
{
// blah blah blah
array1.push(st);
array2.push(ed);
newwindow.document.getElementById('text1').innerHTML = format_array_to_string(array1);
newwindow.document.getElementById('text2').innerHTML = format_array_to_string(array2);
}
function format_array_to_string(a)
{
if(!a.length)
return "";
var sOutput = "";
for( i = 0; i < a.length; ++i )
sOutput += ( i? " ":"" ) + a[i];
return sOutput;
}
This also makes it possible to sort/remove items and then still get the correct output display.
hope this helps.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.