javascript - Reload or Refresh a page using Jquery from local machine - Stack Overflow

I have a html document on my local machine, I created a button using JQuery and set an on click for the

I have a html document on my local machine, I created a button using JQuery and set an on click for the button. When the button is clicked, I want the current index.html page refresh.

This following is in the script tags:

    var refreshButton = '<button id="refresh"> Refresh </button>';
    $body.append(refreshButton);
    $('#refresh').click(function(){
      refresh(forceGet);
    });

i tried, location.refresh(); & window.location.refresh(); & refresh(); but they didnt work.

I have a html document on my local machine, I created a button using JQuery and set an on click for the button. When the button is clicked, I want the current index.html page refresh.

This following is in the script tags:

    var refreshButton = '<button id="refresh"> Refresh </button>';
    $body.append(refreshButton);
    $('#refresh').click(function(){
      refresh(forceGet);
    });

i tried, location.refresh(); & window.location.refresh(); & refresh(); but they didnt work.

Share Improve this question asked Aug 22, 2018 at 21:44 Omar JandaliOmar Jandali 8244 gold badges22 silver badges52 bronze badges 2
  • 2 Do you have any errors in your console? window.location.reload(true); will work. – Jim Wright Commented Aug 22, 2018 at 21:47
  • Have you looked at this answer on how to refresh a page using javascript: stackoverflow./questions/3715047/… – SteveB Commented Aug 22, 2018 at 21:48
Add a ment  | 

2 Answers 2

Reset to default 2
$body.append(refreshButton);

needs to be

$('body').append(refreshButton);

and window.location.reload(true); should work. Try this:

$( document ).ready(function() {
   $('body').append('<button id="refresh"> Refresh </button>');
   $('#refresh').click(function(){
      window.location.reload(true);
   });
});

You need to use window.location.reload().

$('document').ready(() => {
    $('#last-date').html(new Date())
    $('#refresh').on('click', () => {
        console.log('Refreshing...')
        window.location.reload(true)
    })
})
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<button id="refresh">Refresh</button>
<p>Last loaded at <span id="last-date"></span></p>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744201138a4562883.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信