开发者

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开发者_JAVA百科 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜