[英]How to access another page's elements after clicking href link on my website?
I made a website which contains div with href attribute, it links to some social media website.我制作了一个包含带有 href 属性的 div 的网站,它链接到一些社交媒体网站。 my intends to make user go to that website and automatically click on like button, but how can i access that website's elements after it loads up to user?
我打算让用户访问该网站并自动单击喜欢的按钮,但是在加载给用户后如何访问该网站的元素?
its just for practice只是为了练习
<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();
}
it doesn't find any elements on that page.它在该页面上找不到任何元素。
You can't actually do that.你实际上不能那样做。 You can only control what's going on on your site.
你只能控制发生了什么事情在您的网站。 The code you add will run on your site only, so when you do this:
您添加的代码将仅在您的站点上运行,因此当您执行此操作时:
function dropLikeButton() {
window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
document.onload.querySelector(".glyphsSpriteHeart__outline__24__grey_9 u-__7").click();
}
this line这条线
window.location.href="https://www.instagram.com/p/B1G-tU4JFGp/";
will start a redirect to https://www.instagram.com/p/B1G-tU4JFGp/
and then the browser will execute将开始重定向到
https://www.instagram.com/p/B1G-tU4JFGp/
然后浏览器将执行
document.onload.querySelector(".glyphsSpriteHeart__outline__24__grey_9 u-__7").click()
on your site!在您的网站上! The code you wrote won't be there after
instagram
(or any other site) loads instagram
(或任何其他网站)加载后,您编写的代码将不存在
Makes sense?说得通?
As a side note: You can embed sites using <iframe/>
s , but still you won't be able to modify the html.附带说明:您可以使用
<iframe/>
s嵌入网站,但您仍然无法修改 html。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.