Hjælp til ændring og forståelse af script !
Davs Eksperter...!Jeg har dette script, som jeg gerne ville ændre så det passer til min hjemmeside, det er sådan at jeg fremkalder en liste via Database og derudfra skal den indsætte linket i den underliggene side... Er der ikk nogle der vil hjælpe mig med at lave det som eller fortælle mig hvordan jeg gør, så lære jeg da også noget... :)
Med venlig hilsen
Thomas
---------------------
<%
If Request.Form("URL") <> "" OR Request.Form("email") <> "" Then
'Get form elements
strLinkType = Request.Form("selType")
strHyperlinkType = Request.Form("linkChoice")
strHyperlink = Request.Form("URL")
strTitle = Request.Form("Title")
strWindow = Request.Form("Window")
strEmail = Request.Form("email")
strSubject = Request.Form("subject")
'If the http:// part is repeated in the URL then strip it:-
strHyperlink = Replace(strHyperlink, strHyperlinkType, "", 1, -1, 1)
'Escape characters that will course a crash
strHyperlink = Replace(strHyperlink, "'", "\'", 1, -1, 1)
strHyperlink = Replace(strHyperlink, """", "\""", 1, -1, 1)
strTitle = Replace(strTitle, "'", "\'", 1, -1, 1)
strTitle = Replace(strTitle, """", "\""", 1, -1, 1)
strWindow = Replace(strWindow, "'", "\'", 1, -1, 1)
strWindow = Replace(strWindow, """", "\""", 1, -1, 1)
strEmail = Replace(strEmail, "'", "\'", 1, -1, 1)
strEmail = Replace(strEmail, """", "\""", 1, -1, 1)
strSubject = Replace(strSubject, "'", "\'", 1, -1, 1)
strSubject = Replace(strSubject, """", "\""", 1, -1, 1)
'If this is an email mailto then set the email type to mailto:
If strLinkType = "email" Then
strHyperlinkType = "mailto:"
strHyperlink = strEmail
End If
End If
%>
<html>
<head>
<title>Hyperlink Properties</title>
<%
'If this is Gecko based browser link to JS code for Gecko
If COIEenabled = "Gecko" Then Response.Write(vbCrLf & "<script language=""JavaScript"" src=""COIE_javascript_gecko.asp"" type=""text/javascript""></script>")
%>
<script language="JavaScript">
<%
'If this a post back write javascript
If Request.Form("URL") <> "" OR Request.Form("email") <> "" Then
'*********************************************
'*** JavaScript for Mozilla & IE *****
'*********************************************
Response.Write(vbCrLf & "editor = window.opener.document.getElementById('WebWizCOIE');")
'Mozilla and IE use different methods to get the selected text (if any)
If COIEenabled = "Gecko" Then
Response.Write(vbCrLf & vbCrLf & "var selectedRange = editor.contentWindow.window.getSelection();")
Else
Response.Write(vbCrLf & vbCrLf & "var selectedRange = editor.contentWindow.document.selection.createRange();")
End If
'If there is a selected area, turn it into a hyperlink
Response.Write(vbCrLf & vbCrLf & "if (selectedRange != null && selectedRange")
If COIEenabled = "winIE" Then Response.Write(".text")
Response.Write(" != ''){")
'Create hyperlink
Response.Write(vbCrLf & " editor.contentWindow.window.document.execCommand('CreateLink', false, '" & strHyperlinkType & strHyperlink & "')")
%>alert("editor.contentWindow.window.document.execCommand('CreateLink', false, '" & strHyperlinkType & strHyperlink & "')");<%
'Set attributes if required
If (strLinkType = "link" AND (strTitle <> "" OR strWindow <> "")) OR (strLinkType = "email" AND strSubject <> "") Then
'Set hyperlink attributes
Response.Write(vbCrLf & vbCrLf & " var hyperlink = editor.contentWindow.window.document.getElementsByTagName('a');" & _
vbCrLf & " for (var i=0; i < hyperlink.length; i++){" & _
vbCrLf & " if (hyperlink[i].getAttribute('href').search('" & strHyperlinkType & strHyperlink & "') != -1){")
'Set title, window, subject if required
If strLinkType = "link" AND strTitle <> "" Then Response.Write(vbCrLf & " hyperlink[i].setAttribute('title','" & strTitle & "');")
If strLinkType = "link" AND strWindow <> "" Then Response.Write(vbCrLf & " hyperlink[i].setAttribute('target','" & strWindow & "');")
If strLinkType = "email" AND strSubject <> "" Then Response.Write(vbCrLf & " hyperlink[i].setAttribute('subject','" & strSubject & "');")
Response.Write(vbCrLf & " }" & _
vbCrLf & " }")
End If
'Else no selected area so use the hyperlink text as the displayed text
Response.Write(vbCrLf & "}else{")
'Tell that we are maiing a hyperlink 'a'
Response.Write(vbCrLf & vbCrLf & " hyperlink = editor.contentWindow.document.createElement('a');")
Response.Write(vbCrLf & vbCrLf & " hyperlink.setAttribute('href', '" & strHyperlinkType & strHyperlink & "');")
If strLinkType = "link" AND strTitle <> "" Then Response.Write(vbCrLf & " hyperlink.setAttribute('title', '" & strTitle & "');")
If strLinkType = "link" AND strWindow <> "" Then Response.Write(vbCrLf & " hyperlink.setAttribute('target', '" & strWindow & "');")
If strLinkType = "email" AND strSubject <> "" Then Response.Write(vbCrLf & " hyperlink.setAttribute('subject', '" & strSubject & "');")
'Use the text eentered for the link to be a child of the a tag so that it is the screen display
Response.Write(vbCrLf & " hyperlink.appendChild(editor.contentWindow.document.createTextNode('" & strHyperlinkType & strHyperlink & "'));")
'If this is Mozilla then we need to call insertElementPosition to find where to place the image
If COIEenabled = "Gecko" Then
Response.Write(vbCrLf & vbCrLf & " try{" & _
vbCrLf & " insertElementPosition(editor.contentWindow, hyperlink);" & _
vbCrLf & " }catch(exception){" & _
vbCrLf & " alert('" & strTxtErrorInsertingObject & "');" & _
vbCrLf & " editor.contentWindow.focus();" & _
vbCrLf & " }")
'Else this is IE so placing the link is simpler
Else
Response.Write(vbCrLf & vbCrLf & " try{" & _
vbCrLf & " editor.contentWindow.focus();" & _
vbCrLf & " editor.contentWindow.document.selection.createRange().pasteHTML(hyperlink.outerHTML);" & _
vbCrLf & " }catch(exception){" & _
vbCrLf & " alert('" & strTxtErrorInsertingObject & "');" & _
vbCrLf & " editor.contentWindow.focus();" & _
vbCrLf & " }")
End If
Response.Write(vbCrLf & "}")
'Set focus
Response.Write(vbCrLf & vbCrLf & "editor.contentWindow.focus();")
'Close window
Response.Write(vbCrLf & "window.close();")
End If
%>
</script>
<link href="COIE_configuration/default_style.css" rel="stylesheet" type="text/css" />
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" OnLoad="initialise();">
<table width="100%" border="0" cellpadding="3" cellspacing="0" bgcolor="<% = strCOIEpopupTopRowColour %>">
<form method="post" name="frmLinkInsrt">
<tr>
<td colspan="2" bgcolor="<% = strCOIEpopupTopRowColour %>" class="heading"><% = strTxtHyperlinkProperties %></td>
</tr>
<tr>
<td colspan="2" bgcolor="<% = strCOIEpopupCentreRowColour %>"><table width="100%" border="0" align="center" cellpadding="1" cellspacing="0">
<tr>
<td><table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td width="20%" align="right" class="text"><% = strTxtLinkType %>:</td>
<td width="80%"><select name="selType" id="selType" onChange="swapLinkType(this)">
<option value="link" selected>Hyperlink</option>
<option value="email">Email</option>
</select></td>
</tr>
</table></td>
</tr>
<tr>
<td height="240">
<span id="hyperlink">
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td width="20%" align="right" class="text"><% = strTxtAddress %>:</td>
<td width="80%">
<select name="linkChoice" id="linkChoice" onChange="disablePreview(this)">
<option value="http://" selected>http://</option>
<option value="https://">https://</option>
<option value="ftp://">ftp://</option>
<option value="file://">file://</option>
<option value="news://">news://</option>
<option value="telnet://">telnet://</option>
</select>
<input name="URL" type="text" id="URL" size="27" onchange="document.getElementById('Submit').disabled=false;" onkeypress="document.getElementById('Submit').disabled=false;">
<input name="preview" type="button" id="preview" value="<% = strTxtPreview %>" onClick="showPreview(document.getElementById('linkChoice'))">
</td>
</tr>
<tr>
<td align="right" class="text"><% = strTxtTitle %>:</td>
<td><input name="Title" type="text" id="Title" size="40" maxlength="40"></td>
</tr>
<tr>
<td align="right" class="text"><% = strTxtWindow %>:</td>
<td><select name="windowSel" id="windowSel" onChange="document.getElementById('Window').value=this.options[this.selectedIndex].value">
<option value="" selected>Default</option>
<option value="_blank">New Window</option>
<option value="_self">Same Window</option>
<option value="_parent">Parent Window</option>
<option value="_top">Top Window</option>
</select>
<input name="Window" type="text" id="Window" size="12" maxlength="15"></td>
</tr>
<tr>
<td align="right" valign="top" class="text"><% = strTxtPreview %>:</td>
<td><iframe src="COIE_popup_link_preview.asp" id="previewLink" width="98%" height="150px" style="border: #A5ACB2 1px solid;backgroundColor: #FFFFFF;"></iframe></td>
</tr>
</table>
</span>
<span id="mailLink" style="display:none">
<table width="100%" border="0" cellpadding="2" cellspacing="0">
<tr>
<td align="right" class="text"><% = strTxtEmail %>:</td>
<td><input name="email" type="text" id="email" size="40" onfocus="document.forms.frmLinkInsrt.Submit.disabled=false;"></td>
</tr>
<tr>
<td width="20%" align="right" class="text"><% = strTxtSubject %>:</td>
<td width="80%"><input name="subject" type="text" id="subject" size="40" maxlength="50"></td>
</tr>
<tr>
<td> </td>
<td> <br /><br /><br /><br /><br /><br /><br /><br /></td>
</tr>
</table>
</span> </td>
</tr>
</table></td>
</tr>
<tr>
<td align="right" bgcolor="<% = strCOIEpopupBottomRowColour %>" nowrap="nowrap" valign="top"><input type="submit" id="Submit" name="Submit" value=" <% = strTxtOK %> "> <input type="button" name="cancel" value=" <% = strTxtCancel %> " onClick="window.close()"></td>
</tr>
</form>
</table>
</body>
</html>
