how to jump to #unread anchor
how to jump to #unread anchor
Hello,
in received email it is following link, which points to the last unread post: /Forum/viewtopic.php?f=5&t=1&e=1&view=unread#unread
It is possible to jump to the anchor #unread, after page with this link is loaded?
Thank you.
in received email it is following link, which points to the last unread post: /Forum/viewtopic.php?f=5&t=1&e=1&view=unread#unread
It is possible to jump to the anchor #unread, after page with this link is loaded?
Thank you.
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
yes, you read on my mind thank you for report, known problem.
FIXEDV6 will fix this, and any redirected link like these (as well any other):
added on queue into this thread
https://www.axew3.com/w3/forums/viewtop ... f=2&t=1585
where V5 code has been also reported to be patched to fix something else in the while.
I will check to fix on fly if i can find out a moment, even before V6
FIXED
Code: Select all
https://www.phpbb.com/community/viewtopic.php?f=496&t=2554596&e=1&view=unread#unread
https://www.axew3.com/w3/forums/viewtop ... f=2&t=1585
where V5 code has been also reported to be patched to fix something else in the while.
I will check to fix on fly if i can find out a moment, even before V6
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
The V5 overall_footer.html code has been updated to resolve this issue:
https://www.axew3.com/w3/2020/01/phpbb- ... iframe-v5/
To fix:
on added overall_footer.html js code, find this line:
immediately after, add this:
remember to recompile phpBB template.
Note that the code search for h3 elements, containing a elements, than containing strings like this viewtopic.php?p=
so on theme DOM, the posts titles links, needs to exists wrapped like they are into default subsilver, or this line:
$( "h3 > a" ).each(function (e) {
need to change selectors to match on DOM correct post's a links.
Work fine into all themes where post's links a elements are inside an h3 element, like it is on prosilver, but into all themes?
In case as said, the line of code that search for elements on DOM need to be changed to match.
Do not know if there is another way than this to achieve and resolve. I do not think that there is, at moment.
https://www.axew3.com/w3/2020/01/phpbb- ... iframe-v5/
To fix:
on added overall_footer.html js code, find this line:
Code: Select all
var hash = window.location.hash.substr(1);
Code: Select all
if( hash == 'unread' ){
var postN = 1;
$( "h3 > a" ).each(function (e) { // need to match on DOM
ns = this.href.split('#p');
if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
if(ns[1] > postN){
w3lh = ns[1];
}
}
})
if( typeof w3lh != 'undefined' ){
hash = "p" + w3lh;
}
}
Note that the code search for h3 elements, containing a elements, than containing strings like this viewtopic.php?p=
so on theme DOM, the posts titles links, needs to exists wrapped like they are into default subsilver, or this line:
$( "h3 > a" ).each(function (e) {
need to change selectors to match on DOM correct post's a links.
Work fine into all themes where post's links a elements are inside an h3 element, like it is on prosilver, but into all themes?
In case as said, the line of code that search for elements on DOM need to be changed to match.
Do not know if there is another way than this to achieve and resolve. I do not think that there is, at moment.
Re: how to jump to #unread anchor
Hello,
I can confirm that code works. I changed selector based on my page structure. Thank you
I can confirm that code works. I changed selector based on my page structure. Thank you

Re: how to jump to #unread anchor
Hello,
I found problem with this code - If I click to URL with #unread anchor, then page jumps to the latest post instead of the latest unread post.
I found problem with this code - If I click to URL with #unread anchor, then page jumps to the latest post instead of the latest unread post.
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
It scroll to last post, but should instead scroll to, the last unread post, which could be not the last one inserted on thread, when there are more new replies? Do not know how it work, not checked deeply in true, so i will check asap how phpBB execute this task, and how to mimic it.
P.s i see it exist a template S_LOAD_UNREADS var which
so i assume it is the easy and correct way to accomplish with this
mh... just checked, no it is not the way ... let see asap more deeply
p.s
and on fly, i see that could be possible checking for class unreadpost, so the above code need to be little changed to achieve correctly the result
so i assume it is the easy and correct way to accomplish with this
mh... just checked, no it is not the way ... let see asap more deeply
p.s
and on fly, i see that could be possible checking for class unreadpost, so the above code need to be little changed to achieve correctly the result
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
the way was easy, but there is a problem:
class unreadpost, when the forum page display, do not exist anymore, because reversing things i see that this happen:
when the overall_header.html added code fire, that reload pointing to wordpress page, and that run because direct link to board detected, at this point, phpBB already processed all the code that then, set as read the post, and then when iframe load in WP page, class unreadpost is not existent anymore on DOM. So at moment, i think that better than the proposed solution, there is no solution.
... a solution ever exist.
So may let overall_header.html to not fire, when unread detected, leaving the page to follow to the overall_footer.html code, where hash then is possible to be grabbed: then get the value, assign it to a var, that when passed (with the redirect that will fire at this point), will scroll the page forum to the iframe position, exactly where it need to be. It seem to me there is no other possible solution (without changing something into phpBB php code that process the part on top of all this, that's really not a convenient reliable solution, even if maybe there is a listener that could be used for the scope).The page forum code need to be changed to accomplish with this, to scroll it to the passed value.
The problem is that this solution let the phpbb forum display for a while, because the js redirect done on footer and not header.
class unreadpost, when the forum page display, do not exist anymore, because reversing things i see that this happen:
when the overall_header.html added code fire, that reload pointing to wordpress page, and that run because direct link to board detected, at this point, phpBB already processed all the code that then, set as read the post, and then when iframe load in WP page, class unreadpost is not existent anymore on DOM. So at moment, i think that better than the proposed solution, there is no solution.
... a solution ever exist.
So may let overall_header.html to not fire, when unread detected, leaving the page to follow to the overall_footer.html code, where hash then is possible to be grabbed: then get the value, assign it to a var, that when passed (with the redirect that will fire at this point), will scroll the page forum to the iframe position, exactly where it need to be. It seem to me there is no other possible solution (without changing something into phpBB php code that process the part on top of all this, that's really not a convenient reliable solution, even if maybe there is a listener that could be used for the scope).
The problem is that this solution let the phpbb forum display for a while, because the js redirect done on footer and not header.
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
I've try out all the thing, since it is the unique way to resolve this issue:
This is the solution that mimic, may that appear little complicate, but it is not, and works fine.
I will not go to add at moment into online V5 code, since it is an on-fly working code, that i will check on how to add properly into next V6 code, may obscuring with a trick the part where the page reload happen, and shortening code lines, since instructions can be unified. This is extended, to easily understand how the joke work. And it work fine.
Here we go with snippet example
on the js overall_header.html added code, just after
// END MANDATORY CHANGES line,
ADD this:
then change/replace this line:
document.location.replace(href0);
into this:
Save.
(so avoid code to redirect here, if unread detected: let follow to the overall_footer js code, redirect after, when grabbed what needed (read previous post to know why))
Now open overall_footer.html
on added js code, just after this comment:
add the follow:
Save and remember to recompile stale template
This is it
[EDITED]
subsequent my assertion:It scroll to last post, but should instead scroll to, the last unread post, which could be not the last one inserted on thread, when there are more new replies? Do not know how it work, not checked deeply in true, so i will check asap how phpBB execute this task, and how to mimic it.
not true.page-forum need to be changed to accomplish with this
This is the solution that mimic, may that appear little complicate, but it is not, and works fine.
I will not go to add at moment into online V5 code, since it is an on-fly working code, that i will check on how to add properly into next V6 code, may obscuring with a trick the part where the page reload happen, and shortening code lines, since instructions can be unified. This is extended, to easily understand how the joke work. And it work fine.
Here we go with snippet example
on the js overall_header.html added code, just after
// END MANDATORY CHANGES line,
ADD this:
Code: Select all
if(/view=unread#unread/ig.exec(window.location.href) !== null && /viewtopic.php\?/ig.exec(window.location.href) !== null)
{
var w3allUnreadTopic = 1;
}
document.location.replace(href0);
into this:
Code: Select all
if(typeof w3allUnreadTopic == 'undefined'){
document.location.replace(href0);
}
(so avoid code to redirect here, if unread detected: let follow to the overall_footer js code, redirect after, when grabbed what needed (read previous post to know why))
Now open overall_footer.html
on added js code, just after this comment:
Code: Select all
///////////////////////////////////////////////////////////////////////////
// w3all UPDATES for phpBB events
Code: Select all
if(window.self == window.top){
if(typeof w3allUnreadTopic != 'undefined'){
var hash = window.location.hash.substr(1);
if( hash == 'unread' ){
var w3postN = 1000000; // it's assumed that will never exists 1000000 unread posts x topic's page, isn't it?
var w3lh,w3ns,w3Rhash;
$( ".unreadpost" ).each(function (e) {
var hpid = $(this).attr('id');
w3ns = hpid.split('p');
if( w3ns[1] != 'undefined' ){
if(w3ns[1] < w3postN){ // detect when lower and assign
w3lh = w3postN = w3ns[1];
w3Rhash = "p" + w3lh;
}
}
})
if( w3Rhash != 'undefined' ){
// build url and redirect now, with common phpBB url, that point to the right post/hash on thread
// Ex: https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
var w3redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
document.location.replace(w3redirToUnread);
}
}
}
} // END if(window.self == window.top){
This is it
[EDITED]
Re: how to jump to #unread anchor
Hello,
I found two issues with latest code snippet:
1) if I loading forum topic page with this link /viewtopic.php?f=16&t=45554&view=unread#unread and in this topic have not any unread posts then page tries to redirect to this page: /viewtopic.php?p=undefined#undefined
2) I had to a renamed hash variable to hash1 variable because some conflict appears in the console, and code doesn't work.
Thank you for your help.
I found two issues with latest code snippet:
1) if I loading forum topic page with this link /viewtopic.php?f=16&t=45554&view=unread#unread and in this topic have not any unread posts then page tries to redirect to this page: /viewtopic.php?p=undefined#undefined
2) I had to a renamed hash variable to hash1 variable because some conflict appears in the console, and code doesn't work.
Thank you for your help.
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
Ok, thank for report, let check, i will reply with the easy and improved solution asap
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
To me, it was not throwing any error, anyway, when no unread post class found, due to a subsequent click into those kind of unread links, may clicked into notification email, after the topic already visited, what happen was that the code do not follow on redirect.
To complete the task, and make it redirect even when no unread found, redirecting to the last inserted, that obviously is the right one we want to be redirected to in this case, the complete code is little different, using both above snippets like this:
overall_header.html, leave code as is ( as explained here https://www.axew3.com/w3/forums/viewtop ... 4932#p4932 )
while remove completely the previous code into
overall_footer.html, and as before, just after this code comment:
add this code
(and do you remember the line to change into very first snippet where it say need to match on DOM! ? Change also here like you did before, this line $( "h3 > a" ).each(function (e) { // need to match on DOM!
that need to match to elements a inside h3 as above:
it still lack of a sort of trick, that should obscure things, where time latency until redirect happen
To complete the task, and make it redirect even when no unread found, redirecting to the last inserted, that obviously is the right one we want to be redirected to in this case, the complete code is little different, using both above snippets like this:
overall_header.html, leave code as is ( as explained here https://www.axew3.com/w3/forums/viewtop ... 4932#p4932 )
while remove completely the previous code into
overall_footer.html, and as before, just after this code comment:
Code: Select all
///////////////////////////////////////////////////////////////////////////
// w3all UPDATES for phpBB events
(and do you remember the line to change into very first snippet where it say need to match on DOM! ? Change also here like you did before, this line $( "h3 > a" ).each(function (e) { // need to match on DOM!
that need to match to elements a inside h3 as above:
Code: Select all
if(window.self == window.top){
if(typeof w3allUnreadTopic != 'undefined'){
var hash = window.location.hash.substr(1);
if( hash == 'unread' ){
var w3postN = 1000000; // it's assumed that will be never 1000000 posts x page, isn't it?
var w3lh,w3ns,w3nsLowN;
$( ".unreadpost" ).each(function (e) {
var hpid = $(this).attr('id');
w3ns = hpid.split('p');
console.log(w3ns[1]);
if( w3ns[1] != 'undefined' ){
if(w3ns[1] < w3postN){
//console.log('w3ns[1] AND w3postN -> '+w3ns[1]+' - '+w3postN);
w3lh = w3postN = w3ns[1];
w3nsLowN = w3ns[1];
w3Rhash = "p" + w3lh;
}
}
//console.log('hash is ' + hash);
})
// https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
if( typeof w3ns != 'undefined' && typeof w3Rhash != 'undefined' ){
var redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
document.location.replace(redirToUnread);
} else {
var postN = 1;
$( "h3 > a" ).each(function (e) { // need to match on DOM!
ns = this.href.split('#p');
if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
if(ns[1] > postN){
w3lh = ns[1];
}
}
})
if( typeof w3lh != 'undefined' ){
var w3redirToLast = boardU + 'viewtopic.php?p=' + w3lh + '#p' + w3lh;
var w3all_r = w3all0Normalize_phpBBUrl(w3redirToLast);
if(/adm\/index\.php/ig.exec(w3all_r) == null){
var hrefEn = window.btoa(unescape(encodeURIComponent(w3all_r)));
var hre = wordpress_url_page_f + '/?'+ w3all_custom_wp_w3fancyurl + '=' + hrefEn;
document.location.replace(hre);
}
}
}
}
}
} // END if(window.self == window.top){
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
p.s at very late night
to obscure phpBB content before the redirect happen as fast example (could be done better) :
on added js code, just after this line:
add the follow:
to obscure phpBB content before the redirect happen as fast example (could be done better) :
on added js code, just after this line:
Code: Select all
if( hash == 'unread' ){
Code: Select all
$( "body" ).prepend( "<div class=\"preUnreadRedirectBG\"></div>" );
$(".preUnreadRedirectBG").css({ "position":"fixed","top":"0%","bottom":"0%","left":"0%","right":"0%","background": "rgba(0,0,0,1)","z-index": "99999","width":"100%" })
Re: how to jump to #unread anchor
Hello,
thank you for code update. This error appear if I don't rename hash variable.

thank you for code update. This error appear if I don't rename hash variable.

- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
What it mean? What kind of url you try to load to get the error?This error appear if I don't rename hash variable.
Should not because if/when there are no unread, the code should redirect to last one, passing urls like
Code: Select all
https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?f=2&t=26&e=1&view=unread#unread
this line need to match on DOM or as you see, it will return error after, because the code search for unread, and if not found, search for the last one inserted, and if not found again, it make fail the code as before was, so it is mandatory that these elements match on DOM
$( "h3 > a" ).each(function (e) { // need to match on DOM!
The error mean that hash var do not contain a valid value, so when the js search for value based on this it return error. Of course the code can be fixed to avoid this in any case: anyway if no unread found, we should want to redirect to the last one inserted
going to repeat steps to resume:
on the js overall_header.html added code, just after
// END MANDATORY CHANGES line,
ADD this:
Code: Select all
if(/view=unread#unread/ig.exec(window.location.href) !== null && /viewtopic.php\?/ig.exec(window.location.href) !== null)
{
var w3allUnreadTopic = 1;
}
document.location.replace(href0);
into this:
Code: Select all
if(typeof w3allUnreadTopic == 'undefined'){
document.location.replace(href0);
}
Now open overall_footer.html
on added js code, just after this comment:
Code: Select all
///////////////////////////////////////////////////////////////////////////
// w3all UPDATES for phpBB events
Code: Select all
if(window.self == window.top){
if(typeof w3allUnreadTopic != 'undefined'){
var hash = window.location.hash.substr(1);
if( hash == 'unread' ){
$( "body" ).prepend( "<div class=\"preUnreadRedirectBG\"></div>" );
$(".preUnreadRedirectBG").css({"position":"fixed","color": "red","top":"0%","bottom":"0%","left":"0%","right":"0%","background": "rgba(0,0,0,1)","z-index": "99999","width":"100%"})
var w3postN = 1000000; // it's assumed that will be never 1000000 replies x page
var w3lh,w3ns,w3nsLowN;
$( ".unreadpost" ).each(function (e) {
var hpid = $(this).attr('id');
w3ns = hpid.split('p');
if( w3ns[1] != 'undefined' ){
if(w3ns[1] < w3postN){
//console.log('w3ns[1] AND w3postN -> '+w3ns[1]+' - '+w3postN);
w3lh = w3postN = w3ns[1];
w3nsLowN = w3ns[1];
w3Rhash = "p" + w3lh;
}
}
//console.log('hash is ' + hash);
})
// https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
if( typeof w3ns != 'undefined' && typeof w3Rhash != 'undefined' ){
var redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
document.location.replace(redirToUnread);
} else {
var postN = 1;
$( "h3 > a" ).each(function (e) { // need to match on DOM!
ns = this.href.split('#p');
if( typeof ns != 'undefined' && /viewtopic.php\?p=/ig.exec(this.href) != null ){
if(ns[1] > postN){
w3lh = ns[1];
}
}
})
if( typeof w3lh != 'undefined' ){
var w3redirToLast = boardU + 'viewtopic.php?p=' + w3lh + '#p' + w3lh;
var w3all_r = w3all0Normalize_phpBBUrl(w3redirToLast);
if(/adm\/index\.php/ig.exec(w3all_r) == null){
var hrefEn = window.btoa(unescape(encodeURIComponent(w3all_r)));
var hre = wordpress_url_page_f + '/?'+ w3all_custom_wp_w3fancyurl + '=' + hrefEn;
document.location.replace(hre);
}
}
}
}
}
} // END if(window.self == window.top){
It is tested working into any browser here, so let know if still in trouble
- axew3
- w3all User
- Posts: 2113
- Joined: Fri Jan 22, 2016 5:15 pm
- Location: Italy
- Contact:
Re: how to jump to #unread anchor
i'm taking a look for v6 code and looking to this solution, the short and easy:
https://www.axew3.com/w3/forums/viewtop ... 4932#p4932
this part:
where
why to iterate until the highest, and do not stop to the first?
Isn't it?! This is the solution.
Just a remind for the coming v6 code release, many parts of the v5 code needs to be properly fixed.
Also page-forum.php has been updated, but still not committed. It will be together with all nice fixes coming on v6!
https://www.axew3.com/w3/forums/viewtop ... 4932#p4932
this part:
Code: Select all
if(window.self == window.top){
if(typeof w3allUnreadTopic != 'undefined'){
var hash = window.location.hash.substr(1);
if( hash == 'unread' ){
var w3postN = 1000000; // it's assumed that will never exists 1000000 unread posts x topic's page, isn't it?
var w3lh,w3ns,w3Rhash;
$( ".unreadpost" ).each(function (e) {
var hpid = $(this).attr('id');
w3ns = hpid.split('p');
if( w3ns[1] != 'undefined' ){
if(w3ns[1] < w3postN){ // detect when lower and assign
w3lh = w3postN = w3ns[1];
w3Rhash = "p" + w3lh;
}
}
})
if( w3Rhash != 'undefined' ){
// build url and redirect now, with common phpBB url, that point to the right post/hash on thread
// Ex: https://localhost-subdomain.w3host.com/phpbb3/viewtopic.php?p=138#p138
var w3redirToUnread = boardU + 'viewtopic.php?p=' + w3lh + '#' + w3Rhash;
document.location.replace(w3redirToUnread);
}
}
}
} // END if(window.self == window.top){
it is clear to me now, that all the joke can be done in this exact point:// detect when lower and assign
why to iterate until the highest, and do not stop to the first?
Isn't it?! This is the solution.
Just a remind for the coming v6 code release, many parts of the v5 code needs to be properly fixed.
Also page-forum.php has been updated, but still not committed. It will be together with all nice fixes coming on v6!