如何获取/设置当前页面的URL(跨时空浏览器版本运行) [英] How to get/set current page URL (which works across space-time-browsers-versions)

查看:83
本文介绍了如何获取/设置当前页面的URL(跨时空浏览器版本运行)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在发生某些事件时获取/设置当前页面的网址.

I want to get/set URL of the current page upon certain event.

似乎有多种解决方法,如下面的问题/答案所述.

It seems there are more than one approach for doing it as mentioned in questions/answers below.

使用Jquery

Get URL - $(location).attr('href');
Set URL - $(location).attr('href',url);

使用JavaScript

Using JavaScript

Get URL - myVar = window.location.href;
Set URL - window.location.href = "http://stackoverflow.com";

哪种方法适用于时空浏览器版本?

Which approach works across space-time-browsers-versions?

获取JavaScript中的当前URL?

如何重定向到另一个JavaScript/jQuery中的网页?

推荐答案

我认为不需要为此使用jQuery.以下内容将在所有浏览器中正常运行:

I don't see any need to use jQuery for this. The following will work perfectly fine in all browsers:

window.location.href = "http://stackoverflow.com";

或更简单地:

location.href = "http://stackoverflow.com";

这篇关于如何获取/设置当前页面的URL(跨时空浏览器版本运行)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆