如何在JavaScript中更改窗口标题? [英] How to change window title from a frame in javascript?

查看:129
本文介绍了如何在JavaScript中更改窗口标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个免费的公共服务上托管了我的网络应用程序,它在框架集中显示我的网页。 2帧在那里。在最上面的窄框里有他们的广告,底框是我的。我可以在管理面板中设置标题,但无论我的标题标签中是什么,它总是保持不变。在javascript中设置 document.title 不起作用。但是,如果我使用ff的这个框架/显示选项从框架集中分离出来,它将按预期更改窗口/标签标题。

所以可以更改父项文件的标题是从我的框架?



(背景:这将是ajax棋盘游戏,我想在轮到他时以某种方式通知用户)。 b $ b

解决方案

是的,但它必须位于同一个域中(并使用相对路径作为路径)

  window.parent.document.title =您的新标题; 

如果iframe / frame位于不同的域,那么您将获得权限被拒绝的错误。

I hosted my web app on a freehoster service which shows my webpage in a frameset. 2 frames are there. In the top narrow frame there are their ad and the bottom frame is mine. I can set the title in the admin panel but it always remains the same regardless what is in my title tag. Setting document.title in javascript not works. But if I break out from the frameset using the ff's This frame/show option it will change the window/tab title as expected.

So is it possible to change the parent document's title from my frame?

(background: it will be an ajax board game and I want to notify the user somehow when it's his turn.)

解决方案

Yes, but it has to be on the same domain (and use a relative url for a path)

  window.parent.document.title = "Your new title";

If the iframe/frame is on a different domain, then you'll get a permission denied error.

这篇关于如何在JavaScript中更改窗口标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆