从浏览器控制台自动刷新页面

问题描述 投票:6回答:7

美好的一天

我之前从未真正使用过浏览器控制台,所以我真的不知道它能做什么 - 我想要实现的目标如下:

如何从浏览器控制台强制/启动页面上的自动刷新?也就是说,而不是每次都按F5?

此外,控制台是否采取jquery?或者它取决于您所在的网页是否使用jquery?

谢谢!

javascript jquery
7个回答
12
投票

您可以通过运行以下命令从浏览器控制台中刷新页面:

location.reload()

如果你所在的网站加载了jQuery,你将能够运行jQuery命令。

如果网站没有加载jQuery,您可以使用以下书签将jQuery注入页面:

javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){(function(){var d=document.createElement("div"),c=document.getElementsByTagName("body")[0],e=false,g="";d.style.position="fixed";d.style.height="32px";d.style.width="220px";d.style.marginLeft="-110px";d.style.top="0";d.style.left="50%";d.style.padding="5px 10px";d.style.zIndex=1001;d.style.fontSize="12px";d.style.color="#222";d.style.backgroundColor="#f99";if(typeof jQuery!="undefined"){g="This page already using jQuery v"+jQuery.fn.jquery;return f()}else{if(typeof $=="function"){e=true}}function a(i,k){var h=document.createElement("script");h.src=i;var j=document.getElementsByTagName("head")[0],b=false;h.onload=h.onreadystatechange=function(){if(!b&&(!this.readyState||this.readyState=="loaded"||this.readyState=="complete")){b=true;k();h.onload=h.onreadystatechange=null;j.removeChild(h)}};j.appendChild(h)}a("http://code.jquery.com/jquery.min.js",function(){if(typeof jQuery=="undefined"){g="Sorry, but jQuery wasn't able to load"}else{g="This page is now jQuerified with v"+jQuery.fn.jquery;if(e){g+=" and noConflict(). Use $jq(), not $()."}}return f()});function f(){d.innerHTML=g;c.appendChild(d);window.setTimeout(function(){if(typeof jQuery=="undefined"){c.removeChild(d)}else{jQuery(d).fadeOut("slow",function(){jQuery(this).remove()});if(e){$jq=jQuery.noConflict()}}},2500)}})();});

3
投票

如果要使用控制台,只需在控制台中键入document.location.reload()即可。但是如果你想自动创建它 - 它需要在你的代码中。

是的,如果您在代码中包含了库,控制台将采用jquery。

还有一件事,对于自动刷新,你需要类似的东西

setInterval(function(){ document.location.reload() },10*60*1000); 但它不会在控制台中工作,因为在第一次刷新之后,这个男女同校将不再在控制台中。只需将其放在您的代码中即可。


2
投票

你可以使用喜欢

   document.location.reload()

1
投票

如果您的网页包含jQuery。然后jQuery将在控制台中可用:)要刷新,您可以直接在控制台中键入:

window.location.reload()

0
投票

最简单的方法是使用插件。例如,“超级自动刷新”。适用于大多数浏览器


0
投票

使用浏览器选项卡“A”打开并控制另一个浏览器选项卡“B”。这允许您在标签“B”中连续自动重新加载网页,否则您无法控制。重新加载选项卡“B”时,不会删除选项卡“A”中的重新加载命令。

我用它来刷新一个网站,这样它就不会超时并将我注销。此方法不需要jQuery,也不要求您对目标Web页面HTML代码进行任何控制。

打开浏览器新选​​项卡“A”,按F12,选择控制台。输入以下内容:

win1 = window.open("https://www.example.com");

timer1 = setInterval(function(){win1.location.href="https://www.example.com"},10*60*1000);

“win1”是将Javascript变量名称分配给新的浏览器选项卡“B”,以便您可以对其进行Javascript控制。 “timer1”也可以为良好实践和以后的控制分配变量名称。 setInterVal函数运行一个匿名函数来调用“win1”或tab“B”来刷新它的“location.href”,每10分钟一次。

您可能必须打开两个标签。 “固定”它们以便于访问。关闭两个选项卡以停止自动重新加载。选项卡“A”的硬刷新也可能会停止自动重新加载。您也可以使用变量“timer1”来取消自动重新加载。


-1
投票

添加此JavaScript

setTimeout(function () { location.reload(1); }, 5000);

将以下元标记添加到您的网页

<meta http-equiv="refresh" content="5; URL=http://mywebsite/mypage.aspx">

非常感谢安

© www.soinside.com 2019 - 2024. All rights reserved.