建议将Javascript窗口名称传递给php - javascript

我正在使用以下代码打开一个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弹出窗口重新加载页面,这样他们将被强制弹出,那将是很好的。

谢谢 ,

标记

在测试了这些建议之后,有一个常见的问题正是我需要解决的。当用户将页面(收藏夹)添加为书签时,然后返回到已添加标签的页面,他们将不在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>

然后在您的PHP页面中,您可以使用变量windowname,如下所示:

$windowname = $_GET["windowname"];

if ($windowname=="CustomBuilder1") {
    // do something
}

使用JS和PHP更改弹出窗口背景图像 - javascript

我有一个JS函数:function zoom(now) { document.getElementById("popup").style.display = "block"; document.getElementById("photos").style.backgroundImage = …

执行onclick时获得意外令牌 - javascript

我正在使用onclick事件从PHP调用JS函数。这是我的代码:我在一个函数中,因此我需要通过PHP来完成它,因为然后我会返回:$html = '<input type="checkbox" checked value="1" id="setGetSku" name="se…

PHP json_encode数组到javascript关联数组 - javascript

我有一些从PHP中读取的mysqli列。它正在完美地获取和回显。$results = mysqli_fetch_assoc(mysqli_query($conn, $querystring)); echo json_encode($results); //$results = {"title":"Sea Shells"…

PHP-显示特殊字符 - javascript

允许用户输入的代码段//fetch user input and pass it in URL alertify.prompt("Please enter note/remarks for this Form (optional):", function (e,value) { if (e) { alertify.success(…

Mongo汇总 - javascript

我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …