2013-02-05 27 views
0

我有了很多隐藏的内容,我将动画视图使用jQuery的页面。例如,我有一个与#作为href链接的主页面,点击时,我将匹配的div设置为该链接的动画并将其动画化为视图。链接到JavaScript的动画与URL

我想有一个办法可以从网址到这些div直接。目前我正在使用一些JavaScript代码来动画与div匹配的标签的点击。例如,假设我要点击标识为aboutus的标签<a>。我的网址将成为www.myurl.com/homepage.aspx#aboutus,然后JavaScript会采取一切#后,并执行对标签点击这又点击了一个标签和动画,但是我想在div,我想要的东西,我可以通过将例如www.myurl.com/aboutus参考。

我想到了创建每个DIV一个文件夹,并把主要网页的副本显示有用的div,但我不认为这是解决这个问题的最有效方式。有没有人有任何好的想法来实现这一目标?

+0

看看'location.hash' –

+0

你托管的网站的Apache Web服务器上?如果你愿意,'.htaccess'重写可能是答案。 – thirdender

+0

我正在使用IIS7 – user541597

回答

1

如果您在Apache网络服务器托管,在同一文件夹内容创建以下.htaccess文件:

<IfModule mod_rewrite.c> 
    # Enable rewrite engine 
    RewriteEngine on 

    # If the condition "file does not exist"… 
    RewriteCond %{REQUEST_FILENAME} !-f 
    # or the condition "directory does not exist"… 
    RewriteCond %{REQUEST_FILENAME} !-d 
    # rewrite the request as if it came from index.php 
    RewriteRule^index.php [L] 
</IfModule> 

对于IIS服务器,请尝试以下web.config文件:

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.webServer> 
    <rewrite> 
     <rules> 
     <!-- Rewrite URLs of the form 'x' to the form 'index.php?q=x'. --> 
     <rule name="Short URLs" stopProcessing="true"> 
      <match url="^(.*)$" ignoreCase="false" /> 
      <conditions> 
      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> 
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> 
      </conditions> 
      <action type="Rewrite" url="index.php?q={R:1}" appendQueryString="true" /> 
     </rule> 
     </rules> 
    </rewrite> 

    <httpErrors> 
     <remove statusCode="404" subStatusCode="-1" /> 
     <error statusCode="404" prefixLanguageFilePath="" path="/index.php" responseMode="ExecuteURL" /> 
    </httpErrors> 

    <defaultDocument> 
     <!-- Set the default document --> 
     <files> 
     <remove value="index.php" /> 
     <add value="index.php" /> 
     </files> 
    </defaultDocument> 
    </system.webServer> 
</configuration> 

两种配置松散地基于Drupal 7配置文件。他们将所有请求到Web服务器不匹配实际的文件或目录(例如/约-US)实际上返回从index.php不是输出(你可以把index.html那里,而不是您投放静态HTML文件) 。这一切都发生在服务器端...最终用户仍然可以看到他们输入的URL(http://yourdomain.com/about-us)。您可以使用JavaScript捕获该URL(如location.href),并执行您需要做的任何显示更改。