|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Is there any way to specify a target using execCommand('createlink')? I would like to open the link in a new browser window . (target = _blank). The
trouble is, I see no way to pass the target on to execCommand... I urgently need help on this one! Thanks, romel |
|
#2
|
||||
|
||||
|
I know of no way to specify a target. This is a platform-specific tool anyway, isn't it?
|
|
#3
|
|||
|
|||
|
execCommand('createlink')
But is there a way we can modify it . I tried this replaceing the acnore tag like this but for some reason it doesn’t work.
Text = Replace(Text, "href=", "target=""_blank"" href=") |
|
#4
|
||||
|
||||
|
You can manually insert HTML into a document. I assume you are referring to some kind of WYSIWYG setup.
Checkout the 'pasteHTML' method - it allows you to insert literal strings into your document. |
|
#5
|
|||
|
|||
|
Try using showModalWindow function.
You can use a variablle (ex. var link=showModalWindow ('putlink.asp') ). Then you build the putlink.asp page, in wich you can use form (type of address, url name, target). With the submit of the form call a function inside the page that write the full address (<a href.... target= '...'>url</a>), return this address to the parent page. In the parent page, in the insertlink function use the the pasteHTML instead of the execCommand (createLink). I know that i wasn't enough clear. As far as I can i'll drop here an example code. |
|
#6
|
|||
|
|||
|
createlink specifying target
Code:
function createLink() {
var reIMG = /(.*<[Ii][Mm][Gg].*)/ ;
if (!validateMode()) return;
var isA = getEl("A",Composition.document.selection.createRange().pare ntElement());
var str=prompt("Enter link location (e.g. http://www.sbpa.com):", isA ? isA.href : "http:\/\/");
if ((str!=null) && (str!="http://")) {
if (Composition.document.selection.type=="None") {
var sel=Composition.document.selection.createRange();
sel.pasteHTML("<A HREF=\""+str+"\" target=nw>"+str+"</A> ");
sel.select();
} else if (Composition.document.selection.type=="Text") {
var sel=Composition.document.selection.createRange();
if (sel.text.length > 0) {
sel.pasteHTML("<A HREF=\""+str+"\" target=nw>"+sel.text+"</A> ");
} else {
if (reIMG.test(sel.htmlText)) {
sel.pasteHTML("<A HREF=\""+str+"\" target=nw>"+sel.htmlText.replace(/(.*<A[^<]*)(<IMG[^<]*).*$/,'$2')+"</A> ");
} else {
format("CreateLink",str);
}
}
sel.select();
} else {
format("CreateLink",str);
}
}
else Composition.focus();
}
|
|
#7
|
|||
|
|||
|
Hi I had the same problem and I solved it like this:
I use a function to open the link in a new window: function openLink(URI){ win = window.open(URI,"secWin","width=600,height=600,left=100,scrollbars=yes,resiz able=yes,location=yes"); win.focus; } I set the link in the html code using the execCommand like this: function doLink(URI) { if (URI == ''"){ alert("Please enter a URL"); } else{ url = "javascript:openLink('" + URI + "')"; iView.document.execCommand('CreateLink', false, url); //iView is an iFrame where the user edits contents } } The Html code created by the execCommand looks like this <a href="javascript:openLink('http://dbforums.com')">My Link</A> Hope this alternative solves your problem. Padi Last edited by padi : March 25th, 2004 at 05:57 AM. Reason: icons were inserted when :o appeared in the text |
|
#8
|
|||
|
|||
|
I found the easy way to createlink.
I found the easy way to createlink.
We don't need to use execCommand(); Just use pasteHTML() method. ---------------------------------------------------- Code:
<script>
function add_url()
{
str1=prompt("Please insert URL ","");
if(str1 != null)
{
kk = document.selection.createRange();
tt = document.selection.createRange().text ;
str = "<a href=' " +str1+ " ' target='_blank' ><U>" + tt + "</U></a>";
kk.pasteHTML(str);
}
else{
alert("you didn't insert URL ");
}
}
</script>
<a href="javascript:add_url();">Add url</a>
<div CONTENTEDITABLE ID="C1"></div>
Fongming from Taiwan. |
|
#9
|
||||
|
||||
|
This may be considered a modern DOM way to do it.
Code:
<p id="myParagraph">Text</p>
<script>
var someText = document.createTextNode("Go to Devarticles");
var newLink = document.createElement("a");
newLink.href="http://www.devarticles.com";
newLink.title="Devarticles has lots of articles";
newLink.target="_blank";
newLink.appendChild(someText);
document.getElementById('myParagraph').appendChild (newLink);
</script>
|
|
#10
|
|||
|
|||
|
Here is the way I found:
in the page where you have your wysiwyg editor insert this function, called by the "insert link" button. Here is the function: Code:
function inslink ()
{
var slink = showModalDialog("sellink.asp","","dialogHeight: 280px; dialogWidth: 310px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: yes; resizable: Yes; status: yes;" );
if (slink != null){;
var testo=iView.document.selection.createRange().text;
var testohtml=iView.document.selection.createRange();
testohtml.pasteHTML ("<a href='"+slink+">"+testo+"</a>");
}
}
the function call a modal window. Here is the code of the modal window: Code:
<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<script language="JavaScript">
function invialink (){
Link = new Object();
Link.tipo= document.linkform.tipo.value;
Link.Href = document.linkform.url.value ;
Link.Target = document.linkform.target.value;
var linksend = Link.tipo+Link.Href+"' target='"+Link.Target+"'";
window.returnValue = linksend;
window.close ();
}
</script>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<table width="300" border="0" cellpadding="10" cellspacing="0">
<tr>
<td height="208" bgcolor="f0f0f0"><form action="" method="post" name="linkform" id="linkform">
<p><font size="2" face="Arial, Helvetica, sans-serif">tipo
<select name="tipo" id="tipo">
<option value="mailto:">mailto</option>
<option value="http://" selected>http</option>
</select>
</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif"> Url:
<input name="url" type="text" id="url" value="">
</font></p>
<p><font size="2" face="Arial, Helvetica, sans-serif">Target
<select name="target" id="target">
<option value="_self">_self</option>
<option value="_blank" selected>_blank</option>
</select>
</font> </p>
<p align="center"> <br>
<input type="button" name="Submit" value="Invia" onClick="invialink ()">
<br>
<font size="1" face="Arial, Helvetica, sans-serif"><a href="#" onClick="window.close ()">chiudi</a>
</font></p>
</form></td>
</tr>
</table>
</body>
</html>
I know it works only with IE... but... |
|
#11
|
||||
|
||||
|
Nice one MadCowDzz - clearly the best method for todays standards.
|
|
#12
|
|||
|
|||
|
Yes, the way is window.open or parent.frame.document.location
this is your normal link;
The_Link ="http:/www.targnet.com"; now you can transform your link to open urls in a new window: The_Link = "javascript:void window.open('"+The_Link+"');"; if you have to open the url in top frame; The_Link = "javascript:void top.location='"+The_Link+"';"; Now you can use execCommand('createlink')... etc. bye Quote:
|
|
#13
|
|||
|
|||
|
Sorry in the method for open in frame you must NOT use "void", this is the correct way:
The_Link = "javascript:top.location='"+The_Link+"';"; Now you can use execCommand('createlink')... etc. bye |
![]() |
| Viewing: Dev Articles Community Forums > Programming > JavaScript Development > execCommand('createlink')? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|