Skip to content

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

@wingmeng

Description

@wingmeng

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;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions