我正在处理文件myfile.php
。在这个文件中,我有以下代码:
<button type='submit' name='refresh' onclick='refresh()'></button>
<script>
function refresh(){
setTimeout(window.location.href = "summary.php",1000);
}
</script>
单击刷新按钮时,窗口的位置将更新,浏览器将加载文件summary.php
。但是,我想保留在myfile.php
上并在第二个选项卡中刷新文件summary.php
。
javascript参考方案
首先,您必须使用window.open
打开第二个选项卡,并保存对其的引用,以便稍后单击该按钮时可以访问它以重新加载。这是直接从JavaScript访问/控制单独的选项卡的唯一方法。请注意,由于Same-origin policy,您只能对同一域中的页面执行此操作。如果要刷新其他域上的页面,则最好的方法是在标签上设置location.href
。
这是一个非常简单的示例,说明如何使用您的代码:
<button type="button" name="refresh" onclick="refresh()">Refresh</button>
<script>
let secondWindow = window.open('summary.php');
function refresh() {
secondWindow.location.reload(true); // Use true to always force reload from the server
}
</script>
加载summary.php
时,这将导致myfile.php
在新选项卡或窗口中打开。之后,您应该可以单击第一页中的刷新按钮,第二页将重新加载。
如果不想自动打开summary.php
,则可以添加手动打开窗口的方式:
<button type="button" name="open" onclick="open()">Open</button>
<button type="button" name="refresh" onclick="refresh()">Refresh</button>
<script>
let secondWindow;
function open() {
secondWindow = window.open('summary.php');
}
function refresh() {
if (secondWindow) {
secondWindow.location.reload(true); // Use true to always force reload from the server
}
}
</script>
如果不想依靠JavaScript打开第二个选项卡,则可以将Broadcast Channel API作为替代选项。您可以在单击按钮时从第一页发送“刷新”消息,并在第二页看到这些消息之一时刷新自身。
淘汰赛在金字塔中的行为不正确 - javascript我正在使用Pyramid构建一个Webapp,但是Knockout的行为有所不同。我有一个表格: <div data-bind="with: $root.itemToAdd" style="display: none;"> <form data-bind="submit: $root.add…
iframe的占位符内容 - javascript我想在iframe中自动显示数据库中的内容,因为它是创建文档时提交的正文内容。我正在尝试插入JS Php,如下所示:<iframe name="editor" id="editor" class="doc_body" ></iframe></div> <sc…
剃刀付款集成->如何通过关闭按钮X检测剃刀付款模型是否关闭 - javascript当用户关闭而无需付款时,我在CI框架中使用Razorpay,请创建razor支付模型,然后取消订单,我希望按状态更改为已取消的状态触发查询。所以我怎么能检测到这一点。我已经通过单击jQuery单击关闭功能但无法使用... javascript大神给出的解决方案 Razorpay提供了JS方法来检测模式关闭。您编写的任何JS代码都不会在结帐页面上运行,因为它是…
如何使用PHP从动态输入字段捕获数组值? - javascript我正在编写一个在线时间跟踪网页,允许用户将学习时间输入该系统。用户将首先输入名称,然后根据日期输入学习时间。一天中可能会有多个学习时间。以下是我第一页的编码,<head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"…
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …