/    Sign up×
Community /Pin to ProfileBookmark

how to keep text highlighted

Hi Guys,

I am new here and I have searched the forums but have not found any good advice.

I am trying to keep some text highlighted as I click around in the window. Is there a trick or tip on how to keep the text highlighted in an iFrame?

I have an iFrame with some text highlighted and I need to click on an input field inside a layer. The problem is that when I click on the input field to start typing my highlight goes away and the text is no longer highlighted. Again, how do I keep the text highlighted?

Is there even a way to do this?

Thanks for your input, help and/or advice.

to post a comment
JavaScript

12 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — The highlight is only going to show as long as the related object has the focus. When you click into the other object, the focus changes and that is why you can no longer see the highlight -- even though the selected text is still selected in that original object. There is no effective remedy for this. That is just the way it works.

If I may ask, why do you need to see the highlight?
Copy linkTweet thisAlerts:
@JPnycApr 05.2005 — You could change the CSS color and background color properties with javascript. That could give the appearance of being highlighted and wouldn't disappear with loss of focus.
Copy linkTweet thisAlerts:
@GraphfixzauthorApr 05.2005 — I am trying to make a simple link.

When the user highlights a word that they are trying to make into a link and then go the input field where they enter the URL the word is no longer highlighted. I need to keep the word highlighted so that I can know what word I need to apply the url to.
Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — OK, as I said... The text is still highlighted (selected) within the scope of the original object. You do not need to visually "see" this highlight for your JavaScript code to be able to apply the link to it. I have done this before (Simple HTML Editor via JavaScript) so I know that it works as I have stated it.
Copy linkTweet thisAlerts:
@GraphfixzauthorApr 05.2005 — well, somehow it is loosing the focus because the link doesn't get created. I can see that in Netscape it works like it should, however, Netscape does keep the text highlighted as I start typing the URL.

Do I need to set the focus on something?
Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — I'd have to see what methods you're using to try and create this link. Perhaps the real problem here is a cross-browser incompatibility.
Copy linkTweet thisAlerts:
@GraphfixzauthorApr 05.2005 — well here is the function that opens the div with the info to create the link

<i>
</i>
function doLink()
{
var createLink = document.getElementById("createLink").style;
createLink.display = "block";
var createLinkShadow= document.getElementById("createLinkShadow").style;
createLinkShadow.display = "block";
}



createLink is a div that has the input field where user adds the url. Up to this point the text is still highlighted. Once I click on the input field to add the url, the highlight text goes away. I click on a button with an onClick event to exectute the scripts and... well.. no link!
Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — OK, but where is the code that is to operate on the highlighted text to change that highlighted text to a link?
Copy linkTweet thisAlerts:
@GraphfixzauthorApr 05.2005 — keep in mind that these are all in the same html page. Instead of popping up windows I am trying to popup layers.

Point 1: this seems to work in Netscape.

Point 2: if I try to make a link in IE it doesn' t work. However, if I try to create the link a second time the url I entered is already in the input field so I don't have to retype it... hence, it works on IE but only if I have the URL already entered without having to click on the input field.

<i>
</i>
function sendURL()
{
var valueLink = document.getElementById('url').value;
var valuePrefix = document.getElementById('preFix').value;

if(valueLink != "")
{
doLink2(valuePrefix + valueLink);
document.getElementById('createLink').style.display='None';
document.getElementById('createLinkShadow').style.display='None';
}
}




function doLink2(link)
{
iView.document.execCommand('createlink', false, link);
}

Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — OK, this is that for which I was looking:
function doLink2(link)
{
iView.document.execCommand('createlink', false, link);
}

Just as a test, try this:
function doLink2(link)
{
if(document.all) {
document.execCommand('createlink', false, link);
} else {
iView.document.execCommand('createlink', false, link);
}
}
Copy linkTweet thisAlerts:
@GraphfixzauthorApr 05.2005 — it still doesn't create the link. I might just be forced to use browser windows instead of layers.

I just don't like the bulky look of the browser windows.
Copy linkTweet thisAlerts:
@phpnoviceApr 05.2005 — That is the format I use in my Simple HTML Editor. The edit area is a ContentEditable DIV. Works real fine -- lasts a long time.
function selectColor(sel) {
if (sel.selectedIndex == 0) {
document.execCommand("ForeColor", false, "");
} else {
document.execCommand("ForeColor", false, sel.options[sel.selectedIndex].text);
}
}

EDIT: Hey, I just noticed something. When I click on any of my highlighting buttons (bold, italics, underscore, bullets, headings, font face, and color), the highlighting of the text doesn't disappear and, of course, the highlighting functions all work. But, when I click into either of my Find or Replace text boxes, the highlighting [u]does[/u] disappear and, then, [u]none[/u] of my highlighting buttons will work.

So, I'm seeing the same thing you're seeing. Therefore, I don't think there is any fix for this problem -- unless, in IE, you save the selected text into a TextRange object and then restore the selection when you are done typing in the text box.
×

Success!

Help @Graphfixz spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...