Just nu i M3-nätverket
Jump to content

ASP kod för olika webbläsare


Moriax

Recommended Posts

Hittade den här koden här på forumet, och det funkar kanon. Men...

Det funkar ju bara i Explorer miljö, inte i varken mozilla firefox eller netscape. Vet någon varför det inte funkar i andra browsers?

 

För att definiera felet så kan jag säga att den bild man valt i dropdownlistan inte presenteras på skärmen.

 

<form method=post name=form1>
[MÄRK]<%[/MÄRK]
[color="#0000ff"]Const[/color] vdPath = [GRÅ]"/test/images"[/GRÅ]
[color="#0000ff"]Dim[/color] strFolder, strKey, strSelected, strImgURL
[color="#0000ff"]Dim[/color] objFileSystem
[color="#0000ff"]Dim[/color] imgDict
[color="#0000ff"]Set[/color] imgDict = [b]Server[/b].[color="#0000ff"]CreateObject[/color]([GRÅ]"Scripting.Dictionary"[/GRÅ])

[color="#0000ff"]Set[/color] objFileSystem = [b]Server[/b].[color="#0000ff"]CreateObject[/color]([GRÅ]"Scripting.FileSystemObject"[/GRÅ])
strFolder = [color="#0000ff"]LCase[/color]([b]Server[/b].MapPath(vdPath))
[b]Response[/b].Write [GRÅ]"Image folder: "[/GRÅ] & strFolder & [GRÅ]"<br>"[/GRÅ]
[b]Response[/b].Flush

strSelected = [b]Request[/b].Form([GRÅ]"selImages"[/GRÅ])

GetImages strFolder [color="#006400"]' put all files in imgDict for later bubble sort[/color]
[color="#0000ff"]Set[/color] imgDict = SortDictKeys(imgDict)
[b]Response[/b].Write ([GRÅ]"<select name=selImages onchange="[/GRÅ][GRÅ]"this.form.submit()"[/GRÅ][GRÅ]">"[/GRÅ] & vbCrLf & _
[GRÅ]"<option value="[/GRÅ][GRÅ]""[/GRÅ][GRÅ]">Välj en bild...</option> "[/GRÅ] & vbCrLf)
[color="#0000ff"]For[/color] [color="#0000ff"]Each[/color] strKey [color="#0000ff"]In[/color] imgDict.Keys
[b]Response[/b].Write strKey & [GRÅ]":<br>"[/GRÅ]
[b]Response[/b].Write ([GRÅ]"<option"[/GRÅ])
[color="#0000ff"]If[/color] strKey = strSelected [color="#0000ff"]Then[/color] [b]Response[/b].Write ([GRÅ]" selected"[/GRÅ]) 
[b]Response[/b].Write ([GRÅ]" value"[/GRÅ][GRÅ]""[/GRÅ] & imgDict(strKey) & [GRÅ]""[/GRÅ][GRÅ]">"[/GRÅ] & imgDict(strKey) & [GRÅ]"</option>"[/GRÅ] & vbCrLf)
[color="#0000ff"]Next[/color]
[b]Response[/b].Write ([GRÅ]"</select>"[/GRÅ])

[color="#0000ff"]If[/color] [color="#0000ff"]Len[/color](strSelected) > 0 [color="#0000ff"]Then[/color]
strImgURL = vdPath & [GRÅ]"/"[/GRÅ] & strSelected
[b]Response[/b].Write ([GRÅ]"<img src="[/GRÅ][GRÅ]""[/GRÅ] & strImgURL & [GRÅ]""[/GRÅ][GRÅ]" hspace=0 vspace=0 border=1><br>"[/GRÅ])
[color="#0000ff"]End[/color] [color="#0000ff"]If[/color]

[color="#0000ff"]Set[/color] objFileSystem = [color="#0000ff"]Nothing[/color]
[MÄRK]%>[/MÄRK]
</form>
[MÄRK]<%[/MÄRK]

[color="#0000ff"]Function[/color] GetImages(strFolder)
GetImages = [color="#0000ff"]False[/color]
[color="#0000ff"]Dim[/color] objFolder, objSubFolders, objTempFolder
[color="#0000ff"]Dim[/color] f, file
[color="#0000ff"]Dim[/color] strFileName, strExt, strImgURL

[color="#0000ff"]Set[/color] objFolder = objFileSystem.GetFolder ( strFolder )

[color="#0000ff"]Set[/color] f = objFolder.Files 
[color="#0000ff"]For[/color] [color="#0000ff"]Each[/color] file [color="#0000ff"]In[/color] f
[color="#0000ff"]With[/color] file
strFileName = .name
strExt = [color="#0000ff"]LCase[/color](objFileSystem.GetExtensionName(strFileName))
[color="#0000ff"]If[/color] strExt = [GRÅ]"gif"[/GRÅ] or strExt = [GRÅ]"jpg"[/GRÅ] or strExt = [GRÅ]".jpeg"[/GRÅ] or strExt = [GRÅ]"png"[/GRÅ] [color="#0000ff"]Then[/color] 
imgDict(strFileName) = strFileName
[color="#0000ff"]End[/color] [color="#0000ff"]If[/color]
[color="#0000ff"]End[/color] [color="#0000ff"]With[/color]
[color="#0000ff"]Next[/color]

GetImages = f.Count > 0
[color="#0000ff"]Set[/color] f = [color="#0000ff"]Nothing[/color]
[color="#0000ff"]Set[/color] objFolder = [color="#0000ff"]Nothing[/color]

[color="#0000ff"]End[/color] [color="#0000ff"]Function[/color]


[color="#0000ff"]Function[/color] SortDictKeys(TempDict)

[color="#0000ff"]Dim[/color] aItems, aKeys, iC, iBS, iBS2, tempHold, tempItems, SortedDict, f

aItems = TempDict.items
aKeys = TempDict.keys

iC = [color="#0000ff"]UBound[/color](aKeys)-1

[color="#0000ff"]For[/color] iBS=0 [color="#0000ff"]To[/color] iC
[color="#0000ff"]For[/color] iBS2=0 [color="#0000ff"]To[/color] (iC-iBS)
[color="#0000ff"]If[/color] [color="#0000ff"]LCase[/color](aKeys(iBS2)) > [color="#0000ff"]LCase[/color](aKeys(iBS2+1)) [color="#0000ff"]Then[/color] 
tempHold=aKeys(iBS2+1)
aKeys(iBS2+1) = aKeys(iBS2)
aKeys(iBS2)=tempHold
tempItems=aItems(iBS2+1)
aItems(iBS2+1) = aItems(iBS2)
aItems(iBS2)=tempItems
[color="#0000ff"]End[/color] [color="#0000ff"]If[/color]
[color="#0000ff"]Next[/color]
[color="#0000ff"]Next[/color]

[color="#0000ff"]Set[/color] SortedDict = [color="#0000ff"]CreateObject[/color]([GRÅ]"Scripting.Dictionary"[/GRÅ])
[color="#0000ff"]For[/color] f = 0 [color="#0000ff"]To[/color] [color="#0000ff"]UBound[/color](aItems)
SortedDict.Add aKeys(f), aItems(f)
[color="#0000ff"]Next[/color]

[color="#0000ff"]Set[/color] SortDictKeys = SortedDict

[color="#0000ff"]End[/color] [color="#0000ff"]Function[/color]


[MÄRK]%>[/MÄRK]

 

Link to comment
Share on other sites

ASP-koden har ingenting med webläsaren att göra, allting körs på servern. Det är alltså din HTML-kod som det är något tokigt med.

 

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.



×
×
  • Create New...