pass url to a popup

E

Ellie

In my program the user clicks on a link and using the window.open
function, opens a new window.

I pass a url to the new window like this:

<a href="#"
onClick="window.open('../quotescreenwindow.php?enroll_id=enrollwindowprime.php',
'WindowC', 'width=750,height=800,scrollbars=yes');">

In the new window that just opened called quotescreenwindow.php, I
have a button that when clicked, should open yet another window called
enrollwindowprime.php (this is the variable I am passing after the
question mark).

What I cannot do, is to grab this variable that I am passing to the
first window I open and use its content to open the next window.

I am not very experienced and have been piecing this together from
various web sites.

To simplify all of this:

Screen A Opens Popup Window B and passes it a variable with a url
inside of it.

Popup Window B wants to use the variable with the url to open Pop Up
Window C.

I would really appreciate some help.
 
L

Laurent Bugnion

Hi,
In my program the user clicks on a link and using the window.open
function, opens a new window.

I pass a url to the new window like this:

<a href="#"
onClick="window.open('../quotescreenwindow.php?enroll_id=enrollwindowprime.php',
'WindowC', 'width=750,height=800,scrollbars=yes');">

In the new window that just opened called quotescreenwindow.php, I
have a button that when clicked, should open yet another window called
enrollwindowprime.php (this is the variable I am passing after the
question mark).

In a window, you can access the query string using location.search. This
property of the Location object is a string. What's a bit confusing is
that location.search returns "?enroll_id=enrollwindowprime.php"
(including the leading question mark), so you must remove it yourself
using substring.

Here is a generic function returning the query string as a "hashtable".

function getQueryString ()
{
var htstrQuery = new Object();

if ( self.location
&& self.location.search != null
&& self.location.search.length > 0 )
{
var strQuery = self.location.search.substring( 1 );

var astrQueries = strQuery.split( "&" );
for ( var index = 0; index < astrQueries.length; index++ )
{
var astrKeyValue = astrQueries[ index ].split( "=" );
var strValue
= ( ( astrKeyValue[ 1 ] == null )
? "" : astrKeyValue[ 1 ].toString() );

htstrQuery[ astrKeyValue[ 0 ].toString() ] = strValue;
}
}
return htstrQuery;
}


And then you can use:

var htstrQueryString = getQueryString();
var strUrl = htstrQueryString[ "enroll_id" ];

if ( strUrl != null )
{
// Open your new window.
}

<snip>

HTH,
Laurent
 
A

ASM

Ellie a écrit :
To simplify all of this:

Screen A Opens Popup Window B and passes it a variable with a url
inside of it.

Popup Window B wants to use the variable with the url to open Pop Up
Window C.

For your particular need (only 1 variable),
in your file displayed in window B

JS in head :

var newFile = self.location.toString().split('=')[1];

HTML :

<button value="Next"
onclick="
truc=window.open('','','width=300,height=300,resizable=1');
truc.location='../'+newFile;">
 
E

Ellie

Ellie a écrit :
To simplify all of this:

Screen A Opens Popup Window B and passes it a variable with a url
inside of it.

Popup Window B wants to use the variable with the url to open Pop Up
Window C.

For your particular need (only 1 variable),
in your file displayed in window B

JS in head :

var newFile = self.location.toString().split('=')[1];

Again, I am not well versed in all of this. So, this would go in the
head of Window B? It just automatically picks up the variable I sent
attached to the url?
HTML :

<button value="Next"
onclick="
truc=window.open('','','width=300,height=300,resizable=1');
truc.location='../'+newFile;">

My code looks like this:
<a href="#" onClick="window.open('enrollwindow.php', 'WindowD',
'width=750,height=900,scrollbars=yes');">

I tried to put your code in this statement but it opens up a blank
page. I don't understand where in the process it finds the variable I
sent it. I never refer to the variable name in Window B.
 
A

ASM

Ellie a écrit :
My code looks like this:
<a href="#" onClick="window.open('enrollwindow.php', 'WindowD',
'width=750,height=900,scrollbars=yes');">

Here, in your code, 'WindowD' is html name of the popup
You'l use it thru html code : target="WindowD"
It is of no interest in JavaScript (JS doesn't know this WindowD)
I tried to put your code in this statement but it opens up a blank
page. I don't understand where in the process it finds the variable I
sent it. I never refer to the variable name in Window B.

We have window (A) with file ie :'ellie.php'
contains

<a href="#"
onClick="window.open('../quotescreenwindow.php?enroll_id=enrollwindowprime.php',
'WindowB', 'width=750,height=800,scrollbars=yes');">

with enroll_id=enrollwindowprime.php after ? in called url

So, from window (A) you'l open a new popup (B)
with a target of no utility named WindowB
an displaying file 'quotescreenwindow.php'

This file 'quotescreenwindow.php' in popup (B)
only needs to catch from it's self url what is after '='
in order to can open next popup (C)


'quotescreenwindow.php' will be something as :

<html>
<head>
<script type="text/javascript">
var newFile = self.location.toString().split('=')[1];
</script>
</head><body>
<a href="#"
onclick="
truc = window.open('','','width=750,height=800,scrollbars=1');
truc.location = newFile;
return false;"> Popup C </a>
</body></html>


explain :
while downloading the file 'quotescreenwindow.php' in window (B)
browser's javascript will immediately read
newFile = self.location.toString().split('=')[1];

- newFile
is a variable (global)

- self.location.toString().split('=')[1]
translation :
url of displayed file in present window considered as a string
then, using '=' as separator, extract second element

result :
from now, javascript knows the next file to call
newfile = 'enrollwindowprime.php';


The link's onclick :
truc = window.open('','','width=750,height=800,scrollbars=1');
truc.location = newFile;
return false;

- truc will be javascript name of the new popup window (C)
(empty window on this instant)

- truc.location = newFile;
url called in window 'truc' to display is newFile
that's to say 'enrollwindowprime.php'

- return false;
to stop the href of link
 
R

Richard Cornford

ASM wrote:
- self.location.toString().split('=')[1]
translation :
url of displayed file in present window considered as a string
then, using '=' as separator, extract second element

There is nothing to say that a - location - object will have a -
toString - method (and while Windows IE 5 has a - toString - method on
its - location - object, calling it throws an exception), but very good
reason to expect it to have a string type - href - property (and indeed
a string type - search - property), which would be a better subject for
a - split - method call.
result :
from now, javascript knows the next file to call
newfile = 'enrollwindowprime.php';

URI encoding the resource path/name prior to adding it to the query
string, and URI decoding during extraction, would be a good idea.
The link's onclick :
truc = window.open('','','width=750,height=800,scrollbars=1');

Non-resizable windows are not a very good idea as if the size does not
suite the user they will not be able to re-size, while if the size is
suitable they will not suffer for being able to.
truc.location = newFile;
return false;

- truc will be javascript name of the new popup window (C)
(empty window on this instant)
<snip>

Why not:-

truc = window.open(newFile,'','width=750,height=800,scrollbars=1');
return false;

- and have the resource loaded directly into the new window (assuming it
is not pop-up blocked)?

Richard.
 
A

ASM

Richard Cornford a écrit :
ASM wrote:
- self.location.toString().split('=')[1]
translation :
url of displayed file in present window considered as a string
then, using '=' as separator, extract second element

There is nothing to say that a - location - object will have a -
toString - method (and while Windows IE 5 has a - toString - method on
its - location - object, calling it throws an exception), but very good
reason to expect it to have a string type - href - property (and indeed
a string type - search - property), which would be a better subject for
a - split - method call.

By my experience, never I got error with this code above.
However, you're probably right and it could be better to use search

newFile = self.location.search.split('=')[1];
URI encoding the resource path/name prior to adding it to the query
string, and URI decoding during extraction, would be a good idea.

In this case, as newFile is to use to call a file, not necessary

newFile = unescape(self.location.search.split('=')[1]);

(my browsers are too much clever, they automaticaly encode url in
location bar)
Non-resizable windows are not a very good idea as if the size does not
suite the user they will not be able to re-size,

and he can't scroll, he no more find window lifts ? :)
truc = window.open(newFile,'','width=750,height=800,scrollbars=1');

I think OP knew that, my example was more to show difference about
window name in JS and in html
(assuming it is not pop-up blocked)?

of course :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top