Javascript 如何访问另一个页面';在单击我的网站上的href链接后添加哪些元素?

Javascript 如何访问另一个页面';在单击我的网站上的href链接后添加哪些元素?,javascript,click,href,Javascript,Click,Href,我制作了一个包含div和href属性的网站,它链接到一些社交媒体网站。我的目标是让用户访问该网站并自动单击“喜欢”按钮,但在加载到用户之后,我如何访问该网站的元素 只是为了练习 <button onclick="dropLikeButton()">Like</button> function dropLikeButton() { window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";

我制作了一个包含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();
}
Like
函数dropLikeButton(){
window.location.href=”https://www.instagram.com/p/B1G-tU4JFGp/";
document.onload.querySelector(“.glyphsPriteHeart\uuuuuu outline\uuuuu 24\uuuu Gray\uu 9 u-\uuuuu 7”)。单击();
}

它在该页面上找不到任何元素。

您实际上不能这样做。您只能控制您的站点上发生的事情。您添加的代码将仅在您的站点上运行,因此执行此操作时:

功能水滴按钮(){
window.location.href=”https://www.instagram.com/p/B1G-tU4JFGp/";
document.onload.querySelector(“.glyphsPriteHeart\uuuuuu outline\uuuuu 24\uuuu Gray\uu 9 u-\uuuuu 7”)。单击();
}
这条线

window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
将启动重定向到
https://www.instagram.com/p/B1G-tU4JFGp/
然后浏览器将执行

document.onload.querySelector(“.glyphspriteheart\uuuu outline\uuuu24\uuuu grey\u9 u-\uu7”)。单击()
在你的网站上!加载
instagram
(或任何其他站点)后,您编写的代码将不在那里

有道理吗


附带说明:您可以使用嵌入网站,但仍然无法修改html。

什么?您无法通过自己的网站控制用户在其他网站上的行为。@Terkinas不客气!如果这对您有帮助,请接受结束问题的答案:)