Print Page | Close Window

Cursor positioning?

Printed From: Web Wiz Forums
Category: Web Wiz Web App Support Forums
Forum Name: Web Wiz Rich Text Editor (RTE)
Forum Description: Support forum for the Web Wiz Rich Text Editor (RTE).
URL: https://forums.webwiz.net/forum_posts.asp?TID=25881
Printed Date: 29 March 2026 at 10:54am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Cursor positioning?
Posted By: Klankster
Subject: Cursor positioning?
Date Posted: 25 June 2008 at 8:56am
I'm new to this code and inherited it in my website.  Now I have to do some modifications and am not sure how to proceed.  I'm allowing the user to upload images and am displaying them in the editor.  There are two things that can happen:

1) The image is small and I can display it in the image as-is.  No problem, I simply paste it in:

'Insert the image
window.opener.document.getElementById("message").contentWindow.focus(); window.opener.document.getElementById("message").contentWindow.document.execCommand('InsertImage', false, '<% = strTheInsertImage %>'); window.close();

2) The image is too big, so I generate a thumbnail image and insert that, then put in a link to the actual image that they can click on:

'Insert the thumbnail
window.opener.document.getElementById("message").contentWindow.focus(); window.opener.document.getElementById("message").contentWindow.document.execCommand('InsertImage', false, '<% = strTheInsertImage %>');
window.close();

'Build up the string that reflects the full image rez and links to it!
strViewString = "Full Wallpaper View : " & (HTML LINK TO IMAGE HERE)
window.opener.document.getElementById("message").contentWindow.focus();
var htmlLink = window.opener.document.getElementById("message").contentWindow.document.selection.createRange() htmlLink.pasteHTML('<% = strViewString %>'); window.opener.document.getElementById("message").contentWindow.document.execCommand('paste', false, '');
window.close();


The operation in option 1 works great.  The image pastes in and the insertion cursor is right behind it.  Just like I want.

The operation in option 2 doesn't work right -- The first time you insert the image and link, it looks OK but the cursor ends up BEFORE the image.  If you do a second insertion, the second image inserts at the START of the editor window and the second link ends up at the END of the editor window:

[Image2]
[Image1]
[Link1]
[Link2]

Obviously, I'm doing something wrong when I paste in the HTML link because the cursor ends up in the wrong place.  Subsequent insertions are fouled up.

How can I control where the insertion cursor ends up after I paste in the HTML linkage so that subsequent operations go in behind the HTML link?

Suggestions appreciated -- As I said, I'm new to this and am having a hard time finding documentation on this.  This is code that was in place in my application and I'm just reworking it somewhat.





Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net