在子框架内更改favicon

时间:2011-04-09 20:56:20

标签: javascript html frame favicon frameset

我有一个域parent.example,由提供程序设置为将“with masking”转发给child.example。这意味着URL“parent.example”保留在地址栏中,而child.example中的内容则使用框架集显示。

我想添加自定义图标。

到目前为止,我已尝试过,在child.example页面上:

<script type="text/javascript">
  var link = document.createElement("link");
  link.type = "image/x-icon";
  link.rel = "shortcut icon";
  link.href = "http://www.child.example/img/favicon.ico";
  parent.getElementsByTagName("head")[0].appendChild(link);
</script>

但这不起作用。

parent.example的HTML是:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head><title>My Title</title></head>
<frameset rows="100%,*" border="0">
  <frame src="http://child.example" frameborder="0" />
  <frame frameborder="0" noresize />
</frameset>
<!-- pageok -->
<!-- 07 -->
<!-- -->
</html>

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

你不能。

浏览器显示加载到顶层框架中的页面的收藏夹图标。

加载到该页面内的框架中的页面无法修改该页面(same origin policy),因此无法使用JS添加任何favicon数据。

解决方案是获得至少一半体面的托管。

相关问题