Click to See Complete Forum and Search --> : how to pass a large info to a page via window.open
jasongr
08-11-2004, 06:02 AM
Hello
I would like to open a new window using window.open()
I need to be able to pass a large serialized object to that object. The serialized content is generated by PHP.
The serialized object is represented as a long string that I would like to pass to the new window.
It cannot be part of the URL, since the string can be very long (more than 255 characters).
Is there a way to pass such info to the window?
I am using IE 5.5
thanks
sciguyryan
08-11-2004, 06:07 AM
You may try something like:
<script type="text/javascript">
<!--
var NewWin = window.open();
var TheText = "This is a very long string that can not fit into one ";
NewText += "but, as you can see I can split it up into sections so, ";
NewText += "So, its easier to manage.";
NewWindow.innerHTML = NewText.
//-->
</script>
jasongr
08-11-2004, 06:10 AM
this is only useful if I want to display the content.
what if I just want to receive the long text, do some manipulations on it on the server side and then display something else?
Pittimann
08-11-2004, 06:15 AM
Hi!
You could pass the string to a form in the popup and onload of it submit the form to your server side script which handles the rest.
Cheers - Pit
sciguyryan
08-11-2004, 06:16 AM
Originally posted by jasongr
this is only useful if I want to display the content.
what if I just want to receive the long text, do some manipulations on it on the server side and then display something else?
As far as I am aware the same ideas can be apllied to any conent in a window but, as for SSS (Server Side Scripting) I'm still learning :)
jasongr
08-11-2004, 06:20 AM
I need to be able to send the string to the page somehow inside the window.open() function, I cannot count on any form that may be in the source page.
Pittimann
08-11-2004, 06:26 AM
Hi!
Are you trying to play with a page in that window which isn't yours?
Cheers - Pit
jasongr
08-11-2004, 06:27 AM
No, I need to open a new window inside my page and to pass a very large object to the new window.
If the object was less than 255 characters long, I would have sent it as part of the URL, but this is not the case.
Pittimann
08-11-2004, 06:32 AM
Hi!
A blank window or with a html file loaded into it?
If the first one is the case, you could doc.write the form and everything you need to the window. If you load a page into it, which is yours, why not put what you need inside?
Cheers - Pit
jasongr
08-11-2004, 06:37 AM
It's actually a call to a PHP page.
something along the following line:
window.open("test.php");
The PHP page will take the serialized object that I am trying to pass to it and manipulate it
Pittimann
08-11-2004, 06:43 AM
Hi!
That makes my suggestion worth thinking about.
You open a blank page, document.write a form to it, pass your string into the form and autosubmit the form to your php script. This will do the manipulations required and the rest of its' job.
Or: you open your php file in the new window and this file would have the form already inside and...
Regards - Pit
jasongr
08-11-2004, 07:00 AM
Here is my code sample:
This is the source page that shouls launch the new window:
<script type="text/javascript">
var newWindow = window.open("test.php");
newWindow.document.forms['formName'].object.value = '<?php print $serializedObject; ?>';
newWindow.document.forms['formName'].submit();
</script>
This is what test.php looks like
<?php
if (array_key_exists('object', $_POST)) {
// do some server side scripting on the object
}
else {
?>
<html>
<body>
<form name="formName" method="POST" action="error.php">
<input type="hidden" name="object" value=''>
</form>
</body>
</html>
<?php } ?>
For some reason the value of the form is not being updated and the form is not submitted to the server
jasongr
08-11-2004, 07:01 AM
there was an error in the last post:
The action attribute of the form is also "test.php" and not "error.php" as was posted.
The problem still remains
Pittimann
08-11-2004, 07:09 AM
Hi!
A little example just "having been cooked" in my kitchen: http://www.pit-r.de/scripts/popupTransfer.htm
Just view source, to see what is inside.
The source code of the php file is:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<?php
$str=$_POST['blah'];
echo 'Original size of string: '.strlen($str).'<br>';
$str=str_replace('huge','manipulated',$str);
echo $str;
?>
</body>
</html>Cheers - Pit