将Javascript窗口名传递给php的建议
我正在用以下代码打开一个javascript窗口将Javascript窗口名传递给php的建议,javascript,php,Javascript,Php,我正在用以下代码打开一个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,
<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>
函数PopupCenter(页面URL、标题、w、h){
左侧变量=(屏幕宽度/2)-(w/2);
变量顶部=(屏幕高度/2)-(高度/2);
var targetWin=window.open(页面URL,标题,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=no,copyhistory=no,宽度='+w+',高度='+h+',顶部='+top+',左侧='+left);
}
现在我在php页面中加载了一个URL变量(如链接“javawindow=yes”中所示)。现在,当有人将此页面添加到书签时,需要进行特殊处理,因为我需要知道他们是返回书签还是保留在java启动的窗口中
由于窗口名为“CustomBuilder1
”,我需要将窗口名传递给php
,以便验证是否仍在javascript启动的窗口中。如果它们不在javascript启动的窗口中,我需要能够使URL变量自动更新(如果可能)(*如果我能得到Javascropt窗口名tro php,我想我可以找到这一部分)
此外,如果我可以通过javascript弹出窗口强制用户重新加载页面,这样他们就可以强制进入弹出窗口
谢谢
标记
在测试这些建议之后,有一个常见的问题,这正是我需要解决的问题。当用户将页面(收藏夹)添加到书签时,然后返回到书签页面,它们将不在javascriprt窗口中,并且在所有建议的解决方案中,URL变量保持不变,表示它是javascropt窗口,即使它不再是
我需要将JAVAScript窗口名作为变量传递给php,如果与JAVAScript名称不一致,我会做一些事情。但是我认为这是不可能的,因为JAVAScript窗口名只存在于客户端站点上。Amy URL变量将始终具有urlvariable,并且无法检测它是否确实是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>
$windowname = $_GET["windowname"];
if ($windowname=="CustomBuilder1") {
// do something
}
<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
if(isset($_GET['popupTitle']) && $_GET['popupTitle'] == "CustomBuilder1")
{
echo "It's a javascript initiated window.";
}
?>
虽然使用URL参数传递html标题可能不是跟踪用户如何访问页面的最佳方式,但您可以使用@Marco Bonelli的答案来实现这一点 在许多业务设置中(即点击广告),跟踪通过以下两种方法之一执行:
http://example.com/redirect-1
http://example.com/destination
目标
页面如果您使用的是处理路由的框架(大多数MVC都是这样),那么您可以将所有日志逻辑集中到一个控制器操作中,同时单独维护路由。使用GET变量(如
javawindow
)发送窗口名。请尝试以下操作:
<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>
$windowname = $_GET["windowname"];
if ($windowname=="CustomBuilder1") {
// do something
}
<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
if(isset($_GET['popupTitle']) && $_GET['popupTitle'] == "CustomBuilder1")
{
echo "It's a javascript initiated window.";
}
?>
函数PopupCenter(页面URL、标题、w、h){
左侧变量=(屏幕宽度/2)-(w/2);
变量顶部=(屏幕高度/2)-(高度/2);
var targetWin=window.open(pageURL+“&poputtle=“+title,title,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizeable=no,copyhistory=no,width='+w+',height='+h+',top='+top+',left='+left);
}
然后用PHP捕获它,如下所示:
<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>
$windowname = $_GET["windowname"];
if ($windowname=="CustomBuilder1") {
// do something
}
<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
if(isset($_GET['popupTitle']) && $_GET['popupTitle'] == "CustomBuilder1")
{
echo "It's a javascript initiated window.";
}
?>
你不能写以下内容吗?…=window.open(pageUrl+'&title='+title,title,…)