to reproduce same procedure in another location

F

fulio pen

Please open the following page:

http://www.pinyinology.com/content/content3c.html

And press F5 to restart the procedure in the 'typing zone'. The word
disappears and reappears. I like to see this procedure also happens
to the text in the 'listing zone', that is, they disappear and
reappear when pressing F5. The javascript code is in the head area,
but i am pasting some below. Please let me know anything else I need
to do to present my question. Thanks for your help.

function KeyDown()
{
var key=window.event.keyCode;


if (key==8)
{
window.event.returnValue=false;


var r=document.selection.createRange();
r.collapse(false);
r.move("character",-1);
r.collapse(false);


var p=r.parentElement();


if (p.nodeName.toLowerCase()=="sup"){
p.outerHTML="";
return;
}
window.event.returnValue=true;
}
}


function KeyPress()
{
var key=window.event.keyCode;
window.event.returnValue=false;

if (key>=48 && key<=57)
{
var r=document.selection.createRange();
r.collapse(false);


var d=r.duplicate();
d.moveStart("character",-1);
var c=d.text;


var p=d.parentElement();


var b=/[A-Za-z]/.test(c);
//b=b || p.nodeName.toLowerCase()=="sup";


if (b)
{
d.collapse(false);


var s=String.fromCharCode(key);
s=(p.nodeName.toLowerCase()=="sup")? s:"<SUP>"+s+"</SUP>";


d.pasteHTML(s);
d.collapse(false);
d.select();
return;
}
}


if (!(key in {37:1,38:1,39:1,40:1}))
{
var r=document.selection.createRange();
r.collapse(false);
p=r.parentElement();


if (p.nodeName.toLowerCase()=="sup")
{
var s=p.outerHTML;
p.removeNode(true);
r.pasteHTML(s);
r.collapse(false);
r.select();
}
}
window.event.returnValue=true;
}
 
J

Joe Nine

fulio said:
Please open the following page:

http://www.pinyinology.com/content/content3c.html

And press F5 to restart the procedure in the 'typing zone'. The word
disappears and reappears. I like to see this procedure also happens
to the text in the 'listing zone', that is, they disappear and
reappear when pressing F5. The javascript code is in the head area,
but i am pasting some below. Please let me know anything else I need
to do to present my question. Thanks for your help.

Without looking at the page or the code, just from your description I
would copy the text into a session cookie each time a key is pressed. On
page load, look if there's any text in the cookie and if there is, put
it back into the the typing zone. If there's no session cookie present,
then you know it's either an initial load (not an F5 or refresh icon
click) or no text was entered before the F5. By the way, F5 isn't
consistent across all browsers, some use Ctrl-R and on Mac probably that
mac logo key and R.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top