在tvml中可以使用相对链接吗?我在网页中使用它们从来没有遇到过问题,但就是不能在我的tvml文档中工作。
从我的swift中:
static let TVBaseURL = "http://localhost:9001/"
这目前在我的tvml中工作,它位于http://localhost:9001/templates/home.xml
<lockup onselect="getDocument('templates/Featured.xml')">
<img src="http://localhost:9001/graphics/icons/ICON_featured.png" width="313" height="600" />
</lockup>
请注意,onselect
链接是相对的,并且工作正常。但是这不起作用..。
<lockup onselect="getDocument('templates/Featured.xml')">
<img src="../graphics/icons/ICON_featured.png" width="313" height="600" />
</lockup>
发布于 2018-03-11 01:43:18
这完全取决于您如何定义getDocument
函数。但是从您的代码中,它很可能看起来有点像official TVML Programming Guide, sec 8-3中的这个。
function getDocument(extension) {
var templateXHR = new XMLHttpRequest();
var url = baseURL + extension;
loadingTemplate();
templateXHR.responseType = "document";
templateXHR.addEventListener("load", function() {pushPage(templateXHR.responseXML);}, false);
templateXHR.open("GET", url, true);
templateXHR.send();
}
它像你的代码一样使用一个预设的baseURL。因此,get文档支持相对链接。(而不是通用链接。放入完整的http://localhost:9001/index.xml会破坏它。)
在本例中,XMLHttpRequest
对象的open
函数接受完整的url,而不是相对的url。阅读有关XMLHttpRequest open here的更多信息。
总之。这里没有什么是相对的。
但是,您可以使用Javascript的功能执行类似的操作。
当您获得XML文档时,您可以使用document.getElementsByTagName("img")
找到所有的标记,它给出了图像元素的列表。接下来要做的就是用.item(i)
查看它们中的每一个,通过.getAttribute('src')
获取它们的源属性,看看它是以http还是https开头,如果不是,就通过.setAttribute('src', baseUrl+imagePath)
设置新的属性
https://stackoverflow.com/questions/46868439
复制相似问题