I am opening a javascript window with the following code
<script>
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
<a onclick="PopupCenter('/customconfig/index.php?javawindow=yes', 'CustomBuilder1',1080,700);" href="javascript:void(0);"> <img border=0 src = "/images/Animated.GIF"></a>
Now I have in the php page that loads (as you can see in the link "javawindow=yes" as a URL variable. Now when someone bookmarks this page it will need special handling because I need to know if they came back on a bookmark or remain in the java initiated window.
As the window name is "CustomBuilder1
" I need to pass the window name to php
so that I can verify that is is still in a javascript initiated window. If they are not in a javascript initiated window, I need to be able to make the URL variable automatically update if this is possible (* I think I can figure out that part if I can get the Javascropt window name tro php)
Additionally , it would be nice if I can force the user to reload the page by a javascript pop up so they will be in the pop up forcibly.
Thanks ,
Mark
After testing these suggestions there is a common problem which is exactly what I need to get around. When a user bookmarks the page (favorites) , then goes back to the bookmarked page they will not be in a javascriprt window, and in all of the proposed solutions the URL variable remains intact that says it is a javascropt window, even though it is no longer.
I need the JAVAScript window name passed as variable to php, and if not consistemt with the javascript name I then do something. I think however it is not possible because the javascript window name only exists on the client site. Amy URL variable will always have the urlvariable and no way to detect if it is truly a javascript initiated window or not from what I am finding.
Maybe there is a different way but I do not see how.
Just change your popup url adding the variable windowname
to the uri, like this:
<a onclick="PopupCenter('/customconfig/index.php?javawindow=yes&windowname=CustomBuilder1', 'CustomBuilder1',1080,700);" href="javascript:void(0);"> <img border=0 src = "/images/Animated.GIF"></a>
Then in your PHP page you can use the variable windowname like this:
$windowname = $_GET["windowname"];
if ($windowname=="CustomBuilder1") {
// do something
}
while using a URL parameter to pass in the html title might not be the best way to track how your users are accessing the page, you can use @Marco Bonelli's answer to do exactly that.
In many business settings (i.e. click-through advertising), tracking is performed by one of 2 methods:
Using method 1 might be your best alternative, if you are outside of a framework that handles routing. An example of how this is solved:
http://example.com/redirect-1
http://example.com/destination
destination
page.If you are using a framework that handles routing (most MVC's do), then you can centralize all your logging logic into one controller action, while maintaining the routes separately.
Send the window name, using a GET variable like javawindow
. Try something like this:
<script>
function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL + "&popupTitle=" + title, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}
</script>
<a onclick="PopupCenter('/customconfig/index.php?javawindow=yes', 'CustomBuilder1',1080,700);" href="javascript:void(0);"> <img border=0 src = "/images/Animated.GIF"></a>
Then catch it in PHP with something like this:
<?php
if(isset($_GET['popupTitle']) && $_GET['popupTitle'] == "CustomBuilder1")
{
echo "It's a javascript initiated window.";
}
?>