感谢您的回复。抱歉,如果这没有意义,我会再试一次,我可能把事情复杂化了!
我有一个框架集 index.html,其中 top.php 只是 radio 流,其下是 index.php,它是具有导航和一切功能的完整 joomla 网站。
问题是,如果用户通过搜索引擎找到该网站。它将把他们带到 index.php 而他们不会得到带有 top.php 的框架集。我在 top.php 和 index.php 中使用了这段代码:
if(self.location==top.location)self.location="index.html";
除了用户通过搜索引擎查找哪个页面时都会将用户带到 index.php 之外,它的效果很好。
所以我找到了这篇文章(在“更好的方法”部分下查看),它向您展示了如何对其进行编码,因此如果用户的内容位于 about-us.html 上,它将带您到该页面,但仍确保它是在框架集中。 http://scriptasylum.com/tutorials/frameredirect/frameredirect.html
我想要类似的东西,但不幸的是它是一个 Joomla 网站,我没有 page1.html、page2.html 等能够添加代码并根据他们的说明相应地更改它。我只有一页 index.php,它“即时”动态生成页面
所以有没有人知道我可以做我想做的事的方法... 框架集位于 http://www.housocial.com/new/index.html
只是 joomla 部分 http://www.housocial.com/new/index.php
再次感谢
最佳答案
您可以通过 RegExp 提取文件名(我不确定这是否是您要的)
if(self==top)
{
self.location="index.html?"+encodeURIComponent(location.href.match(/\w+\.html$/));
}
处理 GET 参数和 anchor 的更灵活的解决方案:
(
function(url,pattern,query,hash)
{
var filename=location.pathname.match(pattern);
if(filename)
{
url+=filename;
if(query && location.search)
{
url+=location.search;
}
if(hash)
{
url+=location.hash
}
location.href=url;
}
}
)('http://www.housocial.com/new/index.php/', //target-URL
/\w+\.html$/, //pattern to search for
1, //include QUERY_STRING
1 //include hash
)
关于javascript - 修改 JavaScript 代码以在动态页面上使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8250844/