Can we force Javascript/jQuery to load fresh (unmodified) version of page from anchor link in modified page? -


i have jquery function clones elements on page , appends them list, replacing prior content.

for background, items wordpress comments of type - posted since datetime "n" - have been isolated within nested comment structure. nested comment thread hidden, , list of selected comments take place.

if seems... peculiar... note since comments cannot shown/hidden siblings, getting them meant cloning, re-formatting, , appending them in list page element. prior nested structure hidden, , new list of selected comments appears in former space.

so far, good. toggling prior version works fine. works fine except last problem: when clicked, links of type (those linking elements within same page, identified id/hash) behave in less desirable manner.

these internal links, when clicked, appear in browser address bar - .e.g.: ourhome/page/#itemid. if linked item happens displayed in cloned list, function normal anchors: jump location within list. (that's ok, if not ideal possible applications.)

but: if element link hidden, nothing happens except address in browser bar changes.

ideally, automatically force links when clicked either, if external links, load linked page usual, or, if internal, load fresh version of page as displayed in browser bar - is, @ correct linked hash.

unfortunately purpose, location.reload(), window.history.go(0) and, assuming using them correctly, other simple methods refreshing page not reload address in browser bar, prior address of page. actual internal link lost.

preventing default action on anchor links seem serve no purpose here: merely prevent new link ever making browser in first place.

is there simple or complicated way force clicked links load fresh versions of page new anchor/hash?

additional note: works, doesn't go anchor on refreshed page: see correct link in browser bar, instead go other spot on page, possibly determined offset(?). (sub-note: using in example familiar jquery dollar signs instead of "jquery" wordpress requires "no-conflict"):

    $('a').click(function() {      var url = $(this).attr('href');     location.assign(url);     history.go(0);  });  

same results far location.reload(), window.location.href , other minor variations...

new near-solution:

    $('a').click(function(e) {          e.preventdefault();         var url = $(this).attr('href');         window.open(url);      });  

in version open fresh new page in window @ least goes right item linked - no scroll problems except in complicated secondary case (involving wordpress comment reply links, present unique handling problems).

unfortunately, window.open(url,"_self") encounters same problems other methods. so, window.open(url) still best solution far, though still less ideal.

in lieu of screenshots requested

function in use , under testing here: http://ordinary-gentlemen.com/developing/2015/08/comments-since-last-visit-reloaded-reloaded-testing-post/

you'll have leave comment, or visit , return later, access functions (since deal comments left "new since last visit").

i'm leaning toward preferring "near-solution" on alternative envisioned, leave question unanswered @ least in case has enlightening answer.

it seems wanting cachebuster.

 var url = $(this).attr('href')+'?cb'+date.now(); 

also note can push pages browsers history javascript: https://developer.mozilla.org/en-us/docs/web/api/history_api


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -