Showing posts with label URL. Show all posts
Showing posts with label URL. Show all posts

Friday, January 09, 2009

页面重定向与url中的hash在不同的浏览器中的表现

访问时url上带有hash(如http://localhost/a.php#test),重定向到b.php页面时,当前a.php页上hash会被带到b.php页面上,在Firefox/Opera上测试的效果是如此,但IE6上则直接到b.php页,不会将a.php页上hash值带过来。
示例代码:
a.php
<php
header("Location: b.php");
?>
b.php
<php
?>
访问http://localhost/a.php#test,跳转完成后url为http://localhost/b.php#test

Tuesday, December 23, 2008

IE6/IE7上ajax请求的一个bug

UTF-8编码的页面,在IE6/IE7中用ajax方式和普通直接访问方式请求此url,结果是不一样的:
http://localhost/test.php?q=测试中文

ajax: http://localhost/test.php?q=测试中文
服务器端收到的请求,其中的中文参数是以ISO-8859-1编码的(浏览器的默认编码方式),所以服务器端收到的参数其实是乱码的,所以ajax请求URL中的参数一定要经过encode,除了ie之外,其他浏览器测试下来都会自动url encode其中的参数。

非ajax: http://localhost/test.php?q=%E6%B5%8B%E8%AF%95%E4%B8%AD%E6%96%87
服务器端收到正常的UTF-8编码后的参数。

Monday, November 03, 2008

When iframe src is too long in IE6/IE7

在ie中,如果页面内的iframe src的URL长度过长(>2083),ie会请求失败。
微软官方文档说明如下:
Microsoft Internet Explorer 具有最大统一资源定位符 (URL) 长度为 2,083 个字符。 Internet Explorer 也有最多 2,048 个字符的最大路径长度。 此限制适用于同时 POST 请求和 GET 请求 URL。
如果要使用 GET 方法,您被限制为最多个最多 2,048 个字符,减去的实际路径中的字符数。
但是,POST 方法不受到用于提交名称 / 值对该 URL 的大小。 这些对被传输在标头而不是在该 URL。
RFC 2616,"超文本传输协议--HTTP / 1.1,"未指定 URL 长度的任何要求。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>when iframe src is too long in IE6/IE7</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/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xxxxxxxxxxXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"></iframe>
</script>
</body>
</html>
Reference:http://support.microsoft.com/kb/208427/zh-cn

Thursday, July 19, 2007

JavaScript URLs

JavaScript code may appear in a URL that uses the special javascript: pseudo-protocol. The content of such a URL is determined by evaluating the JavaScript code and converting the resulting value to a string. If you want to use a JavaScript URL to execute JavaScript code without returning any document content that would overwrite the current document, use the void operator:
<form action="javascript:void validate( )">

Tuesday, July 03, 2007

Ruby url_encode

require 'cgi'
require 'erb'
require 'uri'

str = "<a href='http://www.google.com'>'Stop!' said Fred</a>"
url_encoded_string = CGI::escape(str)
puts url_encoded_string

url_encoded_str2 = URI::escape(str)
puts url_encoded_str2

url_encoded_3 = ERB::Util.url_encode(str)
puts url_encoded_3

# >> %3Ca+href%3D%27http%3A%2F%2Fwww.google.com%27%3E%27Stop%21%27+said+Fred%3C%2Fa%3E
# >> %3Ca%20href='http://www.google.com'%3E'Stop!'%20said%20Fred%3C/a%3E
# >> %3Ca%20href%3D%27http%3A%2F%2Fwww.google.com%27%3E%27Stop%21%27%20said%20Fred%3C%2Fa%3E

3个方法输出的结果都不一样,最后用ERB::Util.url_encode(str)方法获取得同php5中的urlencode()方法得到的结果。

Tuesday, June 26, 2007

url_encode and url_decode of Ruby


require "ERB"
require "uri"

old = "http://www.google.com/search?q=搜索&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
# URI.escape(old):
new = " http://www.google.com/search?q=%CB%D1%CB%F7&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox-a"
# ERB::Util.url_encode(old)与php中url_encode()相同:
url_encoded = "http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%CB%D1%CB%F7%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Aen-US%3Aofficial%26client%3Dfirefox-a"
# javascript encodeURIComponent: http%3A%2F%2Fwww.google.com%2Fsearch%3Fq%3D%E6%90%9C%E7%B4%A2%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dorg.mozilla%3Aen-US%3Aofficial%26client%3Dfirefox-a
# 跟url_encode中文字符的结果不同


puts URI.escape(old)
puts ERB::Util.url_encode(old)


puts URI.unescape(url_encoded)
puts URI.unescape(new)




Saturday, May 12, 2007

Make a remote URL work like a file upload (in Rails)

Popular @ dzone.com

Want to load a remote URL into an acts_as_attachment/attachment_fu model? Use this little utility class.


class UrlUpload
# Add valid extensions here if you want stuff other than images --
# this helps the webserver set the right content type
EXTENSIONS = {
"image/jpeg" => ["jpg", "jpeg", "jpe"],
"image/gif" => ["gif"],
"image/png" => ["png"]
}
attr_reader :original_filename, :content_type, :attachment_data
def initialize(url)
@attachment_data = open(url)
@content_type = self.attachment_data.content_type
@original_filename = determine_filename
end

private
def determine_filename
# Grab the path - even though it could be a script and not an actual file
path = self.attachment_data.base_uri.path
# Get the filename from the path, make it lowercase to handle those
# crazy Win32 servers with all-caps extensions
filename = File.basename(path).downcase
# If the file extension doesn't match the content type, add it to the end, changing any existing .'s to _
filename = [filename.gsub(/\./, "_"), EXTENSIONS[self.content_type].first].join(".") unless EXTENSIONS[self.content_type].any? {|ext| filename.ends_with?("." + ext) }
# Return the result
filename
end
end



Now when you have the URL you want to load, do something like this:

@model.uploaded_data = UrlUpload.new(url)


Or better yet, make a pseudo-accessor on your aaa/attachment_fu model so you can stay "model-heavy".

def url=(value)
self.uploaded_data = UrlUpload.new(value)
end

Wednesday, March 28, 2007

HTTP_REFERER问题

点击某个链接经过跳转页后到达目标页面时,目标页面取到的HTTP_REFERER_URL为点击链接所在页面的URL,而不是跳转页。也就是说直接从浏览器里进去是跳转页,跳到目标页面时,是取不到HTTP_REFERER的。
另:点Flash页面过来取不到HTTP_REFERER_URL。