在JSON中获取窗口url

Get window url inside JSON

本文关键字:窗口 url 获取 JSON      更新时间:2023-09-26

是否有办法在Json中获得窗口的url。我在下面试过,但不起作用。JSON用于显示小部件。下面是代码片段:

CQ.wcm.ContentFinderTab.getResultsBoxConfig({
            "itemsDDGroups": [CQ.wcm.EditBase.DD_GROUP_ASSET],
            "itemsDDNewParagraph": {
                "path": "foundation/components/image",
                "propertyName": "./fileReference"
            },
            "noRefreshButton": true,
            "tbar": [
                CQ.wcm.ContentFinderTab.REFRESH_BUTTON,
                "->",
             {
            "url": "/bin/wcm/contentfinder/asset/viewnew.json"+window.location.href;
        }, {
            "baseParams": {
                /*"defaultMimeType": "image"*/
                "mimeType": "image"
            },
            "autoLoad":false,
            "reader": new CQ.Ext.data.JsonReader({
                "totalProperty": "results",
                "root": "hits",
                "fields": [
                    "name", "path", "title", "mimeType", "ddGroups", "size", "lastModified", "ck", "templateParams", "imageWidth", "imageHeight"
                ],
                "id": "path"
            })
        })

谢谢

这里没有JSON。只是一个对象文字

您需要从您发送的对象中删除末尾的分号,并可能添加一个参数名。我还将对URL

进行编码
{"url": "/bin/wcm/contentfinder/asset/viewnew.json?url="+
  encodeURIComponent(window.location.href)
},

如果只需要哈希,则不需要参数名和编码

{"url": "/bin/wcm/contentfinder/asset/viewnew.json"+ location.hash},

如果哈希中有比你想要的更多的东西,你需要分割它

{"url": "/bin/wcm/contentfinder/asset/viewnew.json"+ 
 location.hash.split(".html")[0]+".html"
},

或者:

{"url": "/bin/wcm/contentfinder/asset/viewnew.json"+ 
 (location.hash.indexOf(".html")!=-1?location.hash.split(".html")[0]+".html":location.hash)
},