Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

How to make opera forget about a «position» part of the hyperlink just after it is followed? (This is useful when I want to reload page and keep position where I am reading, while the original link has its own position specified.)

Opera-10.52_pre6272, Gentoo

share|improve this question
add comment

3 Answers 3

If you mean that you have followed a link with a fragment specified (the part after the hash sign), why not just press F5 to reload the page? Are you going to the address bar and pressing Enter or something?

share|improve this answer
    
If I used F5 I got positioned according to the fragment identifier. Now I don't. Was this was fixed in new opera? –  ZyX Mar 31 '10 at 9:17
    
@ZyX: I don't know. I don't think I ever saw the behavior you describe. –  Hugh Allen Mar 31 '10 at 11:10
    
Strange: on one site (unixforum.org, Russian forum about linux) I do not get positioned after reload. On other site (habrahabr.ru, Russian IT blog) I do get positioned after reload. So I still want to know how to make Opera forget about a fragment identifier. –  ZyX Mar 31 '10 at 15:48
    
Update: on unixforum I also get positioned on reload, but not if I use link with post number. I used it now only because it was the fastest way to check your answer, so I never noticed such strange behavior. –  ZyX Mar 31 '10 at 15:53
    
Another update: forget about strange behavior, the problem was that I do not get positioned only if I scroll not enough to make the target element invisible. –  ZyX Mar 31 '10 at 15:56
add comment

I just tried again and Opera did as you said - when I reloaded, it went to the fragment ID in the URL. I don't know why I didn't notice it before - perhaps because it's a recent change and I don't often refresh a page I'm in the middle of reading. I would consider it to be a bug - perhaps you would like to report it to Opera Software? I can confirm the same behavior on the Windows version (10.51).

Anyway, here's a workaround: when I'm about to change zoom, which sometimes makes me lose my place, I select some text (preferably a few words from within a single paragraph) and copy it to the clipboard. Then after changing zoom (or in your case reloading), I search for the text I just copied (Ctrl+F).

share|improve this answer
add comment
up vote 0 down vote accepted

This UserJS solves the issue:

// ==UserScript==
// @name PurgeAnchor
// @include *
// ==/UserScript==
(function() {
 var reg=/^(.*)\#(.*)$/;
 var match=reg.exec(location);
 function ObjectPosition(obj) {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
 }
 if(match) {
    location.href=match[1];
    sessionStorage.setItem("anchor", match[2]);
 }
 window.addEventListener("load", (function() {
         var anchor=sessionStorage.getItem("anchor");
         if(anchor!==null) {
             var obj=document.getElementById(anchor);
             if(obj===null) {
                 obj=document.getElementsByName(anchor)[0];
             }
             var pos=0;
             if(obj!==null) {
                 pos=ObjectPosition(obj);
                 window.scrollTo(0, pos);
             }
             sessionStorage.removeItem("anchor");
         }
     }), false);
 })()
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.