2011-11-24 67 views
2

感谢您的回复。对不起,如果没有意义,我会再试一次,我可能会让事情变得复杂!修改要在动态页面上使用的JavaScript代码

我有一个框架集index.html,与top.php只是无线电流,下是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

再次感谢

+1

我已经读了三遍,我不知道你想... – jcolebrand

+0

我不知道为什么,这是什么你发现的代码是硬编码到page1.html ....为什么你不能自己制作框架集? – Brad

+0

update window.location('someurl')。我不明白你在问什么。这就是我所理解的。你想动态改变你的网址,然后使用该逻辑。 – theshadowmonkey

回答

0

您可以提取通过正则表达式的文件名(我不知道这是否是你问的)

if(self==top) 
{ 
self.location="index.html?"+encodeURIComponent(location.href.match(/\w+\.html$/)); 
} 

更灵活的解决方案,需要照顾的GET参数和主持人:

(
    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 
) 
+0

感谢您的回复,我希望以更好的解释重写它。 –

+0

谢谢@ Dr.Molle我试过,但得到 http://www.housocial.com/new/index.php/index.html?null 当它应该是像 http://www.housocial。 com/new/index.php/djs.html –

+0

我的解决方案是在URL末尾查找文件名。我猜这个URL还包含一些GET参数,所以RegExp与href不匹配。您需要将其与location.pathname进行比较。看到我上面更新的答案。 –