2015-01-10 49 views
0

這是令我感到困擾的代碼。我需要找到的代碼,用的fancybox代碼替換,但它拋出一個錯誤:win未定義在ColdFusion中查找並替換

更換mywin值

<cfsavecontent variable="x"> 
mywin = window.open (url,"win",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=ye‌s,width=878,height=810'); 
</cfsavecontent> 

這樣:

mywin = $.fancybox('href' :url,'width': '500'); 

我想像這樣

<cfset a = Replace(x,"mywin = window.open (url,"win",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810');","$.fancybox()","one")> 

更新代碼:

<cfsavecontent variable="foo"> 
     function setmycode() { 
     url = "http://myurl.com?thestep=9&sortBy=1&sortOrder=1"; 
     mywin = window.open (url,"win",'toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810'); 
    mywin.focus(); 
    return false; 
    } 
    </cfsavecontent> 
    <cfset a = Replace(foo,"mywin = window.open (url,""win"",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810');","$.fancybox()","one")> 
    <cfdump var="#a#"> 

回答

6

您需要注意自己的代碼。即使在你的問題中的語法高亮顯示你的錯誤!

如果錯誤中提到了有關「勝利」的內容,並且文本「勝利」由語法高亮顯示器突出顯示......這是錯誤所在的位置。所以你應該仔細檢查。

你必須用雙引號分隔的字符串,但是字符串本身有雙引號:

mywin = window.open (url,"win",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810'); 

所以CF解析器看到周圍"win"第一雙引號作爲字符串的結尾。然後接下來的只是垃圾(並會產生語法錯誤,正如你所看到的)。

如果您的字符串中包含字符串分隔符,則需要將其轉義。 ""( 「Special characters」)

所以你的字符串變成:

mywin = window.open (url,""win"",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810'); 

而分隔時,現在可分析由CF:

<cfset a = Replace(x,"mywin = window.open (url,""win"",'toolbar=yes,location=yes,resizable=yes,copyhistory=yes,scrollbars=yes,width=878,height=810');","$.fancybox()","one")> 
+0

在CFML一個被他們加倍,例如這是否以及如何添加額外的雙引號贏取,這是從cfhttp內容的代碼,我不能做到staright的方式,需要做與coldfusion – jojo

+0

我試過你的代碼它沒有工作檢查編輯的問題請 – jojo

+0

什麼你的意思是「這是來自cfhttp內容的代碼」嗎?你的問題中的代碼示例是否是你正在詢問的*實際代碼?沒有什麼關於''的。請修改您的問題*準確*描述您正在解決的情況,並用*實際代碼*來說明問題。不要依靠我們猜測或承擔事情。閱讀:http://blog.adamcameron.me/2013/09/short-self-contained-correct-compilable.html,以及我鏈接到的文檔。這就是你需要如何解決你的問題,以便他們負責任。 –