[英]Javascript to reload a new tab page
window.open("http://google.com", '_blank');
var childWindow = "http://google.com";
childWindow.location.href = "http://google.com";
我有一個eventAddListener
,它通過按下按鈕在新選項卡上加載http://google.com ,但在它打開 google.com 的新選項卡后,我希望它再次刷新。 不是我的基頁,而是新標簽頁本身。 我展示的代碼只是 5 頁谷歌搜索中不起作用的示例之一。
更新:var win = window.open('google.com', 'New Window'); setTimeout(function () { var win = window.open('google.com', 'New Window'); },3000);
這是我能想到的最好的方法。 它打開新選項卡並“重新加載”新選項卡而不是刷新它。
例如,我想要的是,您單擊新選項卡,粘貼鏈接,然后按 Enter,執行鏈接。 我基本上想要一個執行鏈接的 javascript 函數。
根據我的理解,您希望新選項卡在使用 Javascript 打開后刷新,而不是從運行 Javascript 代碼的當前選項卡。
這不是直接可能的。 您只能從當前選項卡執行 Javascript 代碼。 新打開的選項卡不知道 Javascript 代碼應該運行。 當前選項卡不能傳遞新選項卡執行的指令。
但是,您可以先選擇新打開的選項卡,然后執行 Javascript 代碼來刷新頁面。 但這可能違背了你想要做的事情的目的。
在過去的幾周里,我做了一些類似的工作,下面的代碼對我有用。
索引.html
<button onclick="openTab()">New Tab</button>
<script>
function openTab(){
//this opens a new tab while creating a variable name for that tab
var newTab = window.open("https://google.com","_blank");
//this refreshes that new tab
newTab.location.reload();
}
</script>
只是為了證明這適用於我使用的代碼的新選項卡
<script>
function openTab(){
//this opens a new tab while creating a variable name for that tab
var newTab = window.open("https://google.com","_blank");
//this will alert in the new tab
newTab.alert("New Tab");
//before the following reload code takes effect
//this refreshes that new tab
newTab.location.reload();
}
</script>
希望這就是你正在尋找的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.