URL 中的片段 ID 不起作用 [英] Fragment ID in URL Not Working

查看:30
本文介绍了URL 中的片段 ID 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 7 上使用 Microsoft Internet Explorer 版本 8.我有一个包含片段 ID 的 HTML 文档.当我打开 Internet Explorer 并输入我的 HTML 页面的 URL 并在输入的 URL 中包含片段 ID 时,页面会显示,但显示在请求的部分.下面是我的 HTML 文档的第一部分.请注意,该文档非常大并且包含许多片段 ID.下面列出的只是我文档的一小部分.

I am using Microsoft Internet Explorer version 8 on Windows 7. I have a HTML document that contains fragment IDs. When I open Internet Explorer and enter the URL for my HTML page and include a fragment ID in the entered URL, the page is displayed but not at the requested part. Below is the first part of my HTML document. Note that the document is very large and contains many fragment IDs. What is listed below is just a small part of my document.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="rtl" lang="iw">
<head>
<meta http-equiv="Content-Type" content="text/html">
</head>
<body>
<!-- Lots of lines of text -->
<h2 id="George%20Best">George Best</h2>

我使用以下网址:

file:///C:/HTML/MyPage.html#George%20Best

页面显示在文档中间的某个位置,但离标题George Best"不远.

The page is displayed somewhere in the middle of the document, but nowhere near the heading "George Best".

请注意,如果我输入以下网址,页面将显示在顶部:

Note that if I enter the following URL, the page is displayed at the top:

file:///C:/HTML/MyPage.html

然后,如果我手动将片段 ID 附加到 URL 的末尾,则显示会重新调整并显示文档的正确部分.我相信我错过了一些东西,但我不知道是什么.希望看到这篇文章的人能给我启发.

Then if I manually append the fragment ID to the end of the URL, the display readjusts and the correct section of the document is displayed. I believe I am missing something but I don't know what. I am hoping that someone reading this will be able to enlighten me.

谢谢.

推荐答案

您正在尝试调用片段 ID,但您没有对引用进行 url 编码.试试这个.

You're trying to call the fragment ID but you're not url encoding the reference. Try this instead.

file:///C:/HTML/MyPage.html#George%2520Best

%25 是 % 符号的 url 编码.

%25 is the url encoding for the % sign.

这篇关于URL 中的片段 ID 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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