当我在控制台中键入 window
时。控制台显示 window
是 Window
的实例。是否可以使用 new Window()
创建新的窗口对象。我试过了,但它抛出错误 TypeError: Illegal constructor
我的问题与Location
对象有关。我可以使用 Location
创建一个新对象吗?
我需要它,以便我可以将 location
对象上可用的方法应用于我的链接。
我试图访问 Location 对象但没有成功。
我正在使用 Chrome 控制台
。
最佳答案
尝试使用 Location
来操纵任意 URI 将无法按预期工作。 Location
对象/类型不是一般的 URI 容器,而是与 DOM 及其导航状态的特殊契约。
我找到了这个 URI JavaScript type by webr3通过谷歌,YMMV:
URI Type for javascript
- Supports all kinds of URI (URL, URN, any scheme).
- Relative URI Resolution
- All classes extend the native String implementation.
- Pure ECMA-262 implementation of URI spec (RFC-3986)
- Works Client or Server side, (V8 / node.js compatible).
关于javascript - 可以创建 Location 的实例吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12680790/