更改 url 后在 Firebug 中执行命令

execute command in firebug after change of url

本文关键字:执行 命令 Firebug url 后在 更改      更新时间:2023-09-26

我正在尝试在URL上执行一小段javascript,然后设置一个10秒的间隔计时器来更改URL并加载另一个页面,然后执行相同的代码段...但是在新页面加载后,脚本停止...有没有办法保持脚本在全局级别运行?或者可能是可以为我提供相同结果的替代解决方案?也许是一个免费的自动化软件并允许这样做?我想作为测试方案的一部分启动这个,但我是新手

这是我放在控制台中的代码我想在第一个加载的页面上运行 getStuff,然后重定向,然后在第二个页面上再次运行它

function getStuff(){   
    var innerHtml = document.getElementById('carInfo').innerHTML;
    console.log(innerHtml);
}
function redirect() {
    location.href = http://localhost/details.php?id=2; // go to 2nd page, want to increment the id as next step
    setTimeout("getStuff()",5000); // wait 5 seconds to load, run getStuff
}

getStuff(); // getStuff() the 1st time (current open page)
var interval = setInterval("redirect()",10000); // redirect() after 10 seconds to a new url then getStuff...loop on this

您有以下选择:

  1. 使用 AJAX 加载页面。这样,您就不会离开运行脚本的页面。

    getStuff -> AJAX GET -> Append to page -> getStuff -> AJAX GET ....
    
  2. 调用getStuff并在您打算加载的每个页面上重定向。您还可以使用 cookie 来指示您需要在该页面上运行该"重新加载器"。

    cookie set -> getStuff -> redirect -> read cookie -> if cookie ok -> getStuff -> redirect...
                                           '--> if not ok -> stop