简体   繁体   English

如果我想在chrome开发工具上运行代码段时单击新页面上的按钮,该怎么办

[英]What should I do if I want to click button on the new page while running snippet on chrome dev tools

I try to run some JS snippet in chrome dev tools , but not sure what I should do here. 我尝试在chrome开发工具中运行一些JS代码段 ,但不确定在这里应该做什么。 Can anyone help here? 有人可以帮忙吗? Thanks. 谢谢。

Take StackOverflow site for example. 以StackOverflow网站为例。 The script clicks the navigator tab "Jobs" to a new page then clicks the button "Create alert" on it. 该脚本单击导航器选项卡“作业”到新页面,然后单击其上的“创建警报”按钮。 在此处输入图片说明 see image for more information. 请参阅图像以获取更多信息。

f1 works separately and also f2, but they do not work if I put them together. f1和f2分别工作,但是如果我将它们放在一起,它们将无法工作。 what should I do if I hope them work together? 如果希望他们能一起工作该怎么办?

 function f1(){ //click the nav-jobs document.getElementById("nav-jobs").click(); } function f2(){ // create the button "Create alert" on the job page document.getElementById("reg-alert-model").click(); } f1(); setTimeout(f2, 5000); 

Function call f2() will not occur because a page transition has already occurred after executing f1() . 执行f1()之后已经发生页面转换,因此不会发生函数调用f2() f1()

JavaScript function calls do not persist in the call stack between page transitions. 在页面转换之间,JavaScript函数调用不会保留在调用堆栈中。

When a page is reloaded or a new page is loaded, the entire context of the previous page is cleared/reset. 重新加载页面或加载新页面时,将清除/重置上一页的整个上下文。 So you can't keep a timer running over a document change. 因此,您不能让计时器在文档更改上运行。 Naturally, when running them separately (no, not seperately ), there are no context changes, so it works as you expect. 自然地,当分别运行它们(不,不是单独运行 )时,没有上下文更改,因此可以按预期工作。 But if you change the context in between, everything is lost, including the timer. 但是,如果您在两者之间更改上下文,则所有内容都将丢失,包括计时器在内。 Using the developer tools does not do any magic in keeping the context, it does not really matter whether you run it in the console or in the "page code". 使用开发人员工具对保持上下文没有任何魔力,无论是在控制台中还是在“页面代码”中运行它都没有关系。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Chrome 开发工具或 Firefox 开发工具中查看哪些 JS 改变了我的元素的样式? - How do I see what JS is changing style to my elements in Chrome dev tools or Firefox dev tools? 在单击“提交”按钮时,我要获取成功警报,然后单击“确定”,我应该重定向到PHP的新页面 - On click of submit button I want to get an success alert and then clicking on OK I should get redirected to a new page for PHP 如何在 Chrome Dev Tools 中停止调试器? - How do I stop the debugger in Chrome Dev Tools? 如何在Chrome Dev Tools中使用jQuery遍历执行上下文? - How do I traverse Execution Contexts with jQuery in Chrome Dev Tools? 当我单击导航栏中的按钮或其他按钮时,它会将我重定向到一个名为 undefined 的页面,但我想要做的是打开一个引导模式 - When I click a button in navbar or other button it redirects me to a page called undefined but what I want to do is open a bootstrap modal 如何单击下载页面 chrome 中的保留按钮 - how do I click a keep button in download page chrome 我想在tinyMCE图像工具中捕获“确定”按钮的单击事件 - I want to catch click event of Ok button in tinyMCE image tools 如何判断哪个版本的javascript chrome dev工具正在运行? - How to tell what version of javascript chrome dev tools is running? 我想在单击按钮时重新加载页面并在新选项卡中执行路由操作 - I want to reload the page on button click and perform the route action in new tab 当我单击特定的“addToBasket”按钮时,我不想更改所有“addToBasket”按钮。 只有点击的按钮应该改变 - I do not want all the "addToBasket" buttons to change when i click on a specefic "addToBasket" button. Only the clicked button should change
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM