简体   繁体   English

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

[英]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.

相关问题 单击链接后我的网站中的新页面打开后如何更改 1 CSS 行? - How to change 1 CSS line after a new page within my website opens after clicking a link? 在 React JS 中单击 Card 后如何添加指向另一个网站的链接 - How to add a link to another website after clicking on Card in React JS 单击链接后如何在另一个页面上进行确认框起作用? - How to make confirmation box on another page after clicking a link, work? 如何使2重叠 <div> 通过单击另一个的href和一个按钮来依次显示 <div> ? - How to make 2 overlapping <div>s to be shown after one another by clicking a href and a button from another <div>? 如何在单击带有href =#的链接时停止页面加载? - How to stop page load while clicking on link with href=#? 尝试通过单击另一页面上的链接来访问页面上的某个部分时出错 - Error trying to access a section on a page by clicking on a link that is on another page 点击链接后如何go到页面顶部? - How to go to the top of the page after clicking the link? 单击特定的<a>href链接一次</a>后,在整个网站上永久显示隐藏的div - Show hidden div permanently throughout website after clicking on a specific <a> href link once 单击href链接时页面刷新 - Page Reload while clicking on the href link 托管我的网站后如何使用 php 重定向到另一个页面 - how to redirect to another page using php after hosting my website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM