![](/img/trans.png)
[英]How to change 1 CSS line after a new page within my website opens after clicking a link?
[英]How to access another page's elements after clicking href link on my website?
我制作了一個包含帶有 href 屬性的 div 的網站,它鏈接到一些社交媒體網站。 我打算讓用戶訪問該網站並自動單擊喜歡的按鈕,但是在加載給用戶后如何訪問該網站的元素?
只是為了練習
<button onclick="dropLikeButton()">Like</button>
function dropLikeButton() {
window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
document.onload.querySelector(".glyphsSpriteHeart__outline__24__grey_9 u-__7").click();
}
它在該頁面上找不到任何元素。
你實際上不能那樣做。 你只能控制發生了什么事情在您的網站。 您添加的代碼將僅在您的站點上運行,因此當您執行此操作時:
function dropLikeButton() {
window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
document.onload.querySelector(".glyphsSpriteHeart__outline__24__grey_9 u-__7").click();
}
這條線
window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
將開始重定向到https://www.instagram.com/p/B1G-tU4JFGp/
然后瀏覽器將執行
document.onload.querySelector(".glyphsSpriteHeart__outline__24__grey_9 u-__7").click()
在您的網站上! instagram
(或任何其他網站)加載后,您編寫的代碼將不存在
說得通?
附帶說明:您可以使用<iframe/>
s嵌入網站,但您仍然無法修改 html。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.