![](/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.