我正在打开一个javascript窗口,其中包含以下代码
<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>
现在我在php页面中加载了(正如你在链接"javawindow=yes"中看到的那样)作为URL变量。现在,当有人给这个页面添加书签时,它将需要特殊处理,因为我需要知道他们是回到书签上还是留在java启动的窗口中。
由于窗口名称为"CustomBuilder1
",我需要将窗口名称传递给php
,这样我就可以验证它是否仍在javascript启动的窗口中。如果它们不在javascript启动的窗口中,如果可能的话,我需要能够使URL变量自动更新(*我想如果我能获得Javascropt窗口名称tro.php,我就能弄清楚这一部分)
此外,如果我能通过javascript弹出窗口强制用户重新加载页面,这样他们就会强制出现在弹出窗口中,那就太好了。
谢谢,
标记
在测试了这些建议之后,有一个常见的问题,这正是我需要解决的问题。当用户为页面(收藏夹)添加书签,然后返回到添加书签的页面时,它们将不在javascrprt窗口中,并且在所有提出的解决方案中,URL变量保持不变,表明它是javascropt窗口,即使它不再是。
我需要将JAVAScript窗口名称作为变量传递给php,如果与JAVAScript名称不一致,我会做一些事情。然而,我认为这是不可能的,因为javascript窗口名称只存在于客户端网站上。AmyURL变量将始终具有URL变量,并且无法从我所发现的内容中检测它是否真的是一个javascript启动的窗口。
也许有不同的方法,但我不知道怎么做。
只需更改弹出url,将变量windowname
添加到uri中,如下所示:
<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>
然后在您的PHP页面中,您可以使用这样的变量窗口名:
$windowname = $_GET["windowname"];
if ($windowname=="CustomBuilder1") {
// do something
}
使用类似javawindow
的GET变量发送窗口名称。试试这样的东西:
<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>
然后在PHP中用这样的东西捕捉它:
<?php
if(isset($_GET['popupTitle']) && $_GET['popupTitle'] == "CustomBuilder1")
{
echo "It's a javascript initiated window.";
}
?>
虽然使用URL参数传递html标题可能不是跟踪用户访问页面的最佳方式,但您可以使用@Marco Bonelli的答案来做到这一点。
在许多业务设置(即点击广告)中,跟踪通过以下两种方法之一执行:
- 使用重定向
- 使用指向同一文档的备用URL
如果您在处理路由的框架之外,那么使用方法1可能是最好的选择。如何解决这个问题的一个例子:
- 用户单击链接,将其带到URL:
http://example.com/redirect-1
- 重定向-1处的脚本记录访问,然后重定向到
http://example.com/destination
- 您可以根据需要设置任意多个重定向URL,以跟踪用户访问
destination
页面的方式
如果您使用的是一个处理路由的框架(大多数MVC都这样做),那么您可以将所有日志记录逻辑集中到一个控制器操作中,同时单独维护路由。