简体   繁体   English

如何从第一页的按钮重新加载第二页?

[英]How can I reload page two from button in page one?

I've button in page one and I wanna to refresh page two when I click on button in page one ?? 我在第一页按钮,当我点击第一页的按钮时,我想刷新第二页?

I've been using this code but not working : 我一直在使用这段代码,但没有工作:

var url_home = "{{ url('/') }}";

$(document).ready(function()
{  
    $("#refreshDIV").click(function()
    {
        $("#refreshDIV").reload(url_home);
    });
});

You can use local storage to accomplish this in the browser as long as both pages are open at the same time. 只要两个页面同时打开,您就可以使用本地存储在浏览器中完成此操作。

In your page ONE , you can set local storage like below: 在您的第一 ,可以设置本地存储象下面这样:

$("#refreshDIV").click(function()
{
    localStorage.setItem('refreshOtherPage', '0');
    localStorage.setItem('refreshOtherPage', '1');
});

Then in page TWO , you can add a listener script to automatically reload the page: 然后,在第二页,你可以添加一个监听器脚本来自动重新加载页面:

//Fired from page ONE tab

    $(window).on('storage', function (e)
    {
        var storageEvent = e.originalEvent;

        if ((storageEvent.key == 'refreshOtherPage')
            && (storageEvent.oldValue == '0')
            && (storageEvent.newValue == '1'))
        {
          // DO WHATEVER YOU WANTED TO DO WHEN THAT BUTTON WAS CLICKED HERE
        }
    });

It seems you mix javascript and jquery. 看来你混合了javascript和jquery。 The reload() function does not exist in jquery. jquery中不存在reload()函数。 However, you are close to answer your question. 但是,您即将回答您的问题。 But you'll have to put your 'second page' into a div#id. 但是你必须将你的'第二页'放入div#id。

<div id="page1"><button id="reload" ...></div>
<div id="page2">the second page, no page headers</div>

And your jquery 而你的jquery

var url_home = "{{ url('/') }}";

$(document).ready(function()
{  
    $("button#reload").click(function()
    {
        //font awesome spinner while loading, temporarily replaces #page2
        $("#page2").html('<div class="fas fa-sync fa-spin fa-2x fa-fw"></span>'); 
        $("#page2").load(url_home);
    });
});

You could make the button dynamic by replacing it with a boostrap <a> button and catch the url let url_home = $(this).attr('href'); 您可以通过用boostrap <a>按钮替换它来使按钮动态化并捕获url let url_home = $(this).attr('href'); , don't forget to preventDefault() and trigger on $("a#reload"> if you go for this option. ,不要忘记使用preventDefault()并触发$("a#reload">如果你选择这个选项。

If I understand you correctly, you can do that by naming your link's target attribute when you first launch the new tab. 如果我理解正确,您可以在首次启动新选项卡时命名链接的目标属性。 Then every time you click that link used to launch the tab, it will reload the page in that tab for you. 然后,每次单击用于启动选项卡的链接时,它都会为您重新加载该选项卡中的页面。

In page A you add a link to page B like this: 在页面A中,您可以像这样添加指向页面B的链接:

<a href="/page-b" target="page_b">Foo</a>

Now click that link and it will open page B in new tab. 现在单击该链接,它将在新选项卡中打开页面B.

Click again and it will reload page B. 再次单击它将重新加载页面B.

This will not work when someone directly goes to /page-b though. 当有人直接访问/page-b时,这不起作用。

There is no need to write any Javascript or something on server side. 无需在服务器端编写任何Javascript或其他内容。 However, if you must create a button dynamically you may adapt this approach to suite your needs. 但是,如果必须动态创建按钮,则可以调整此方法以满足您的需求。 Hope this helps! 希望这可以帮助!

If you meant reloading part of the same webpage, that is easily achievable through AJAX. 如果您想重新加载同一网页的一部分,那么可以通过AJAX轻松实现。

暂无
暂无

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

相关问题 我如何对data-dismiss =“ modal”有两种影响;一种是重新加载父页面,另一种是不加载 - How i can have two effects for my data-dismiss=“modal” ;one to reload the parent page , while the other without loading 我的{{link-to}}帮助者之一正在触发页面重新加载。 我如何找出导致该页面完全重新加载的原因? - One of my `{{link-to}}` helpers is triggering a page reload. How can i figure out what is causing that page to reload completely? 如何运行查询并重新加载页面? - How can I run query and reload page? 如何单击链接但不重新加载页面? - How can I click a link but not reload the page? 如何保存数据并使用一个按钮重新加载页面(单击) - How to save data and reload the page with one button (Click) 在Webpack中更改所需模块之一后,如何重新加载页面? - How can I reload the page when I changed one of my required modules in Webpack? 返回并重新加载页面 - 一个按钮 - Go back and reload page - one button 我如何才能在按钮单击时从C#页面调用两个javascript函数 - How can i call two javascript function from c# page both on button click 当我重新加载页面并且没有选中 Laravel 6.0 中的单选按钮之一时,如何一次只显示一个表单 - How do i show only one form at a time when i reload the page and didn't check one of the radio button in Laravel 6.0 按下按钮后如何重新加载页面? - How can you make a separate page reload when a button is pressed?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM