我有一个域parent.example,由提供程序设置为将“with masking”转发给child.example。这意味着URL“parent.example”将保留在地址栏中,child.example中的内容将使用框架集显示。
我想添加一个定制的favicon。
到目前为止,我在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>

有什么想法吗?

最佳答案

你不能。
浏览器显示加载到顶层框架中的页面的fav图标。
加载到该页内部框架中的页无法修改该页(same origin policy),因此无法使用JS添加任何favicon数据。
解决办法是至少要有一半像样的主机。

关于javascript - 从子框架中更改收藏夹图标,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5607857/

10-12 07:27
查看更多