在我的网站上单击 href link 后如何访问另一个页面的元素?

How to access another page's elements after clicking href link on my website?

我做了一个网站,其中包含 div 和 href 属性,它链接到一些社交媒体网站。我打算让用户转到该网站并自动点击“赞”按钮,但我如何在用户加载后访问该网站的元素?

仅供练习

<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.