[英]How to run Javascript in newly opened window?
假設我有以下代碼。
window.open(url, windowName, "height=500,width=500")
// This will open a new window with the url.
myFunction();
// Run this function on the newly opened window instead of
// the old one because I need to find a link on the new page.
現在, myFunction() 卡在舊窗口上。
更新:新的 url 是另一個域。
您有多種選擇:
編輯存儲在url
的網頁的源代碼,以包含您希望在網頁打開時運行的自定義代碼。 如果您只想在網頁從彈出窗口打開時運行此代碼,您可以將 url 命名為“webpage.html?run_custom_code”,然后在 webpage.html 中使用僅在window.location.href.indexOf('run_custom_code') > 0
你可以打開一個網頁,它的唯一目的是運行 javascript: window.open('javascript:alert()');
盡管根據您的編輯,這對您來說似乎沒有用。
使用另一種語言,例如 PHP,您可以在其中使用$html = file_get_contents($url);
類的內容獲取另一個網頁的內容$html = file_get_contents($url);
對另一個 url 執行ajax 請求(如果它位於同一個域中)並抓取結果以找到您的鏈接。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.