2011-11-24 70 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進行比較。看到我上面更新的答案。 –