Open a url in a new page automatically
Moderator: General Moderators
Open a url in a new page automatically
I have a url stored in $link . How can I make the page open that url in a new window automatically on refresh (refresh is in <META http-equiv="refresh" content="330">?
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You can't do it using PHP you would have to use JavaScript but you can pass the PHP variable to the JavaScript code, see:
viewtopic.php?t=1030
Mac
viewtopic.php?t=1030
Mac
[Edit]I don't get any parse error now, but instead it prints the link instead of open the link in a new window. It doesn't execute the javascript at all. Here's the output:
[/edit]
I am getting an parse error in the line with window.open.
Here is some of the code:
The error message i receive is:
what am i doing wrong? $link is containing a string like this: http://some_domain.com/some_page.php?x=456586
Code: Select all
Connected successfullyhttp://www.xxxx/page.php?x=226705Thank you for adding 1 follower to '.$nick.'.I am getting an parse error in the line with window.open.
Here is some of the code:
Code: Select all
echo '<script language="Javascript" type="text/javascript">
if ( 0 )
{
window.open('$rowї"link"]', "outwarlink", "WIDTH=800, HEIGHT=600 ,
resizable=yes, status=no");;
}
</script>';
/* Printing results in HTML */
echo 'Thank you for adding 1 follower to <B>'$nick'</B>.';
and so on....Code: Select all
Parse error: parse error, expecting `','' or `';'' in /mnt/home3/s/st/stfjord/public_html/crewbuilder.php on line 50Code: Select all
<html>
<title>New Window Onload</title>
<head>
<script language="JavaScript">
<!--
function open_link(url,name)
{
new_window = window.open('<?=$link?>','<?=$linktitle?>', ' menubar,resizable,dependent,status,width=300,height=200,left=10,top=10')
}
// -->
</script>
</head>
<?
if ($link){
echo "<body onload="open_link()">";
} else {
echo "<body>";
}
?>
Your new window will open when this document loads
</body>
</html>still not working. See for your self: http://home.no.net/stfjord/crewbuilder.php
here's the code:
Are you sure I shouldn't have any arguments in the call to open_link in <body onload=.....>
here's the code:
Code: Select all
<META http-equiv="refresh" content="330">
<HTML>
<TITLE>::Pheonix Army's CrewBuilder::</TITLE>
<HEAD>
<script language="JavaScript">
<!--
function open_link(url,name)
{
new_window = window.open('<? $link ?>','<? $nick ?>')
}
// -->
</script>
</HEAD>
<?
//11 entries in database so far. Will have to make it find number of
//entries automatically later when it grows big.
$firstEntry=1;
$lastEntry=11;
$randNr = rand (1, 11);
/* Connecting, selecting database */
$db = mysql_connect("some_server", "user", "passw")
or die("Could not connect");
print "Connected successfully";
mysql_select_db("outwar") or die("Could not select database");
/* Performing SQL query */
$query = "SELECT nick, rank, link FROM members WHERE nr='$randNr'";
$result = mysql_query($query) or die("\nQuery failed");
// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop
// Note: If you put extract($row); inside the following loop, you'll
// then create $userid, $fullname, and $userstatus
$row = mysql_fetch_assoc($result);
extract($row);
/* //Proving that nick, link and rank is extracted from DB:
echo $nick;
echo $link;
echo $rank;
*/
$linktitle=$nick;
if ($link){
echo "<body onload="open_link()">";
} else {
echo "<body>";
}
/* Printing results in HTML */
// echo 'Thank you for adding 1 follower to <B>'; echo $nick;echo'</B>.';
/* Free resultset */
mysql_free_result($result);
// /* Closing connection */
// mysql_close($link);
/* Disconnecting from database*/
$connStatus = (mysql_close($db)) or die("Terminating database connection failed");
?>
</BODY>
</HTML>Very odd indeed.
I did a few tests and i came to the conclusion that meta refreshing does not work if the variable that the meta tag is going to forward to is defined within the page. Like so:
It only worked for me when i used it with the GET method (put it in the url).
Here is the working source:
http://oromian.port5.com/test-javapopup ... ource=true
Here is the working site:
http://oromian.port5.com/test-javapopup ... apopup.php
and here it is with a link loaded
http://oromian.port5.com/test-javapopup ... p://smx.ca
Enjoy.
I did a few tests and i came to the conclusion that meta refreshing does not work if the variable that the meta tag is going to forward to is defined within the page. Like so:
Code: Select all
<?php
$self = $PHP_SELF;
<meta http-equiv="refresh" content="5; url=<?=$self?>?link=http://forums.devnetwork.net">
?>Here is the working source:
http://oromian.port5.com/test-javapopup ... ource=true
Here is the working site:
http://oromian.port5.com/test-javapopup ... apopup.php
and here it is with a link loaded
http://oromian.port5.com/test-javapopup ... p://smx.ca
Enjoy.