conflict between query-part of url and visited-state of url

G

~greg

I have links on an index page like this:

<a href="link" onclick="DoOnClick('link')"> page title </a>

-where the DoOnClick("link")
just adds a query part to the url before executing:

location.href = "link?query";

( this is done in order to maintain certain state information
--(instead of using cookies.))

I also use something like this:

a.link { ...different... }
a.visited { ...colors... }
a.hover { ...for each of these... }

in a css file for the index pages,
in order to distinguish the already-visited page-links.


The problem is that it's not working right.

It works with JavaScript disabled,

But with JavaScript enabled, it's only the
first-clicked page link that gets marked as having
been visited. Subsequent pages don't get marked.

Apparently the full "link?query" is being put
in the browser history, - not "link".

And since "link?query" doesn't match exactly any "link"
on the page, --none of them get marked as having been visited.

( However, - the really odd thing, - is that it does work
-right -- in my local mirror of the site!
(--I'm using the latest IE browser.)

Anyway, my question is,
can anyone think of a way around this?

Perhaps by somehow using the JavaScript's "history" object
to force recording of "link" instead of, or in addition to, "link?query",
in the user's visited-link history, --so that they'll all get marked as such
on the index pages?


Thank you.

~Greg.
 
D

Dietmar Meier

~greg said:
I have links on an index page like this:

<a href="link" onclick="DoOnClick('link')"> page title </a>

-where the DoOnClick("link")
just adds a query part to the url before executing:

location.href = "link?query";

You'd better add the query string to the link's href property:

<a href="[...]" onclick="return DoOnClick(this)"> page title </a>
[...]
function DoOnClick(oLink) {
var query = "foo=bar&baz=42"; // change this to your needs
oLink.href += "?" + query;
return true;
}

See <for some explanation.

Probably this solves your described problem, too; I didn't test
your code, since I assume it will work with the above changes.

ciao ,dhgm
 
G

~greg

<a href="[...]" onclick="return DoOnClick(this)"> page title </a>
[...]
function DoOnClick(oLink) {
var query = "foo=bar&baz=42"; // change this to your needs
oLink.href += "?" + query;
return true;
}

See <for some explanation.

Probably this solves your described problem, too; I didn't test
your code, since I assume it will work with the above changes.

ciao ,dhgm


- no - it doesn't solve it. --- same thing happens.
When I following on the links on the site, the get recorded
in the browser history with the query parts attached.
(But when I follow them on the local mirror, they're recorded
without the query.)


This is good though, --thanks!,
I wouldn't have learned about it otherwise,
and it it saves space,

( although i don't understand it - --especially why "return true" part
(--- i also tried "return false, -- and it doesn't work)..



Well, -- Here's one of the index pages:
http://lcngarc.twoshakesofalambstail.com/199409.html?0000012

(- and that's good
- i got it with an example query on it --

(--- hmmm, -- Maybe that's it, -- that the query's are like that,
-- not like "?a=b" ,. .the browser might not recognize it as a query on the url?? ...)



Here's an example of a link on the index page:
3 <a name='n3' class='clA' id='id3' href='1994/09/1994090075.html' onclick="return Nav(this)">Welcome! `<i>Perry E.
Metzger</i>`</a>



And the relevant JavaScript follows.


~greg
---------------------------------------------


var state = '';

function Nav( addr )
{
addr.href += state;
return true;
}

function RealTop(el)
{
var y = el.offsetTop;
var el2 = el.offsetParent;
while (el2 != null)
{
y += el2.offsetTop;
el2 = el2.offsetParent;
}
return y;
}


function DoOnLoad()
{
state = location.search.substring(0,6);

var target = location.search.substring(6);

if(target != '')
{
var el = document.getElementById( 'id' + target);

el.style.color = "#FF0000";
el.style.background = "#FFFFFF";
el.style.textDecoration = "line-through";

var h = 200; // wild guess for the default
var h1 = document.body.clientHeight; // NN n/a IE ok
var h2 = window.innerHeight; // NN 4 IE n/a
if ( (h1 != null) && (h1 != 0)) h = h1;
else if ( (h2 != null) && (h2 != 0)) h = h2;

h = Math.floor(h/2);

var y = null;

if( el.offsetTop){y = RealTop(el)}
else if (el.y) {y = el.y}

if ( y != null ) { scrollBy(0, y - h)}
else{location.href = '#n' + target }
}

}
 
D

Dietmar Meier

~greg said:
When I following on the links on the site, the get recorded
in the browser history with the query parts attached.
(But when I follow them on the local mirror, they're recorded
without the query.)

Does "on the local mirror" mean "using the file: protocol"?
Then it's completely usual that some browsers totally ignore
the searchpart.

ciao, dhgm
 
G

~greg

Does "on the local mirror" mean "using the file: protocol"?
yes


Then it's completely usual that some browsers totally ignore
the searchpart.


well (IE6) doesn't ignore completely
- it in the sense that the search part
does show in the address bar,
--and it's acted on by the javascript,

It's just in the history folder that the search part
of urls isn't included when using file:// protocol,
so that right links get marked as visited
---using file:// protocol,

--but not when using html:// protocol.

yep, -- that's the problem ...
:)


~greg.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top