Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第 59 期(W3C 标准-JavaScript-BOM):location 位置操作 #62

Open
wingmeng opened this issue Jul 14, 2019 · 0 comments
Open

第 59 期(W3C 标准-JavaScript-BOM):location 位置操作 #62

wingmeng opened this issue Jul 14, 2019 · 0 comments

Comments

@wingmeng
Copy link
Collaborator

location 是 JavaScript 中最有用的 BOM 对象之一,它提供了当前文档信息和一系列导航功能。

任务1: 使用 JS 使当前页面跳转到 https://www.github.com

答案
window.location = 'https://www.github.com';  // 方法1
location.href = 'https://www.github.com';  // 方法2
location.assign('https://www.github.com');  // 方法3

任务2: 将 URL 修改为 https://www.github.com#issue1

答案
location.hash = 'issue1';

任务3: 将 URL 修改为 https://www.github.com?user=wingmeng

答案
location.search = 'user=wingmeng';

任务4: 将 URL 修改为 https://www.gitee.com

答案
location.hostname = 'www.gitee.com';

任务5: 将 URL 修改为 https://www.gitee.com/market

答案
location.pathname = 'market';

任务6: 将 URL 修改为 https://www.gitee.com:8080/market

答案
location.port = 8080;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant