JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 25th, 2003, 02:35 AM
romel romel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 romel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Question execCommand('createlink')?

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

Reply With Quote
  #2  
Old September 25th, 2003, 07:50 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Send a message via ICQ to dhouston
I know of no way to specify a target. This is a platform-specific tool anyway, isn't it?

Reply With Quote
  #3  
Old September 25th, 2003, 08:11 AM
romel romel is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Posts: 3 romel User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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=")

Reply With Quote
  #4  
Old September 26th, 2003, 07:26 AM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
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.

Reply With Quote
  #5  
Old October 18th, 2003, 01:01 PM
gereko3d gereko3d is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 gereko3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 40 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old March 11th, 2004, 03:06 PM
doubloon doubloon is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 2 doubloon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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();
}

Reply With Quote
  #7  
Old March 25th, 2004, 06:53 AM
padi padi is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Posts: 1 padi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 06:57 AM. Reason: icons were inserted when :o appeared in the text

Reply With Quote
  #8  
Old October 10th, 2005, 01:13 PM
fongming fongming is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2005
Posts: 1 fongming User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 21 m 31 sec
Reputation Power: 0
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.

Reply With Quote
  #9  
Old October 11th, 2005, 08:44 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
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>

Reply With Quote
  #10  
Old October 18th, 2005, 04:33 AM
gereko3d gereko3d is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 5 gereko3d User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 29 m 40 sec
Reputation Power: 0
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...

Reply With Quote
  #11  
Old October 18th, 2005, 11:53 PM
stumpy's Avatar
stumpy stumpy is offline
May contain nuts.
Dev Articles Regular (2000 - 2499 posts)
 
Join Date: Aug 2002
Posts: 2,056 stumpy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 44 m 22 sec
Reputation Power: 0
Nice one MadCowDzz - clearly the best method for todays standards.

Reply With Quote
  #12  
Old October 21st, 2006, 06:12 PM
padidat padidat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 2 padidat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 21 sec
Reputation Power: 0
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:
Originally Posted by romel
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

Reply With Quote
  #13  
Old October 21st, 2006, 06:22 PM
padidat padidat is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2006
Posts: 2 padidat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 23 m 21 sec
Reputation Power: 0
Talking Yes, the way is window.open or parent.frame.document.location (2)

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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJavaScript Development > execCommand('createlink')?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap