HTML-editor skal åbne link eksternt.
Jeg arbejder med en editor som skal åbne links enten internt eller eksternt. Nu linkes alt videre i samme vindue, og jeg vil gerne have muligheden for at lade brugeren bestemme.Jeg arbejder i ASP, men det er ikke har problemet ligger. Se http://exp.dk/spm/370203. Der er en længere indføring i problemet.
Jeg ved ikke hvor jeg skal starte men her er lidt kode:
<SCRIPT>
// Default format is WYSIWYG HTML
var format="HTML"
// Set the focus to the editor
function setFocus() {
textEdit.focus()
}
// Execute a command against the editor
// At minimum one argument is required. Some commands
// require a second optional argument:
// eg., ("formatblock","<H1>") to make an H1
function execCommand(command) {
textEdit.focus()
if (format=="HTML") {
var edit = textEdit.document.selection.createRange()
if (arguments[1]==null)
edit.execCommand(command)
else
edit.execCommand(command,false, arguments[1])
edit.select()
textEdit.focus()
}
}
// Selects all the text in the editor
function selectAllText(){
var edit = textEdit.document;
edit.execCommand('SelectAll');
textEdit.focus();
}
function newDocument() {
textEdit.document.open()
textEdit.document.write("")
textEdit.document.close()
textEdit.focus()
}
function loadDoc(htmlString) {
textEdit.document.open()
textEdit.document.write(htmlString)
textEdit.document.close()
}
// Initialize the editor with an empty document
function initEditor() {
var htmlString = parent.document.all.EditorValue.value;
textEdit.document.designMode="On"
textEdit.document.open()
textEdit.document.write(htmlString)
textEdit.document.close()
textEdit.focus()
}
// Swap between WYSIWYG mode and raw HTML mode
function swapModes() {
if (format=="HTML") {
textEdit.document.body.innerText = textEdit.document.body.innerHTML
textEdit.document.body.style.fontFamily = "monospace"
textEdit.document.body.style.fontSize = "10pt"
format="Text"
}
else {
textEdit.document.body.innerHTML = textEdit.document.body.innerText
textEdit.document.body.style.fontFamily = ""
textEdit.document.body.style.fontSize =""
format="HTML"
}
// textEdit.focus()
var s = textEdit.document.body.createTextRange()
s.collapse(false)
s.select()
}
window.onload = initEditor
</SCRIPT>
og
function makeUrl(){
sUrl = document.all.what.value + "test" + document.all.url.value;
doFormat('CreateLink',sUrl);
}
og til sidst:
function doFormat(what) {
var eb = document.all.editbar;
if(what == "FontName"){
if(arguments[1] != 1){
eb._editor.execCommand(what, arguments[1]);
document.all.font.selectedIndex = 0;
}
} else if(what == "FontSize"){
if(arguments[1] != 1){
eb._editor.execCommand(what, arguments[1]);
document.all.size.selectedIndex = 0;
}
} else {
eb._editor.execCommand(what, arguments[1]);
}
}
Hjæælp....
