如何将字符串转换为Location对象?

如何将字符串转换为Location对象?

问题描述:

可能重复:
在javascript中创建新的Location对象

Possible Duplicate:
Creating a new Location object in javascript

如果用户输入的字符串是URL,最简单的方法是将其转换为位置对象(如window.location),因此我可以使用obj.hostname?

If the user inputs a string that is a URL, what's the easiest way to turn it into a Location object (like window.location) so I can use methods and properties like obj.hostname?

不知道是否可以创建Location对象,但是本文介绍了如何使用锚标记实现相同的效果:

Don't know if you can create a Location object, but this article explains how to use an anchor tag for the same effect:

http://james.padolsey.com/javascript/parsing -urls-with-the-dom/