简体   繁体   中英

Re-render a webpage

I was wondering if there was a way to render a webpage over again, thus calling all the onload events over again, and redrawing the css?

For example, say you changed the pathway of a javascript file that is linked to an onload event and the edited page needed to reload without a refresh in order for the change to take affect.

tested, now is working:

function fireEvent(element,event){
    if (document.createEventObject){
    // dispatch for IE
    var evt = document.createEventObject();
    return element.fireEvent('on'+event,evt)
    }
    else{
    // dispatch for firefox + others
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent(event, true, true ); // event type,bubbling,cancelable
    return !element.dispatchEvent(evt);
    }
}

setTimeout(function(){

    var links = document.getElementsByTagName("link");
    var st = [];
    for(var x=0;x<links.length;x++)
    if(links[x].getAttribute("rel") == "stylesheet")
    {
        st.push(links[x]);
        links[x].wasAtt = links[x].getAttribute("href");
        links[x].setAttribute("href", "");
    }
    setTimeout(function()
    {
        for(var x =0;x<st.length;x++)
            st[x].setAttribute("href", st[x].wasAtt);
        setTimeout(function(){
            fireEvent(window, "load");
        },1000);
    },1000);
},5000); // test reload after five seconds

"reload without a refresh" sounds a bit confusing to me.

However I do not know if this is what you are looking for, but window.location.reload() triggers a page reload and thus will load your linked javascript files.

But changing linked files and reload the page is not a good thing to do. It would be better if your dynamic files are loaded in a dynamic way like using Ajax. So you do not need to reload the whole page. Frameworks like JQuery, ExtJS or others provide methods to do this easily.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM