开发者

How to replace text of current document URL using javascript

开发者 https://www.devze.com 2023-04-11 23:19 出处:网络
Ex: Following is my current document. 开发者_Python百科http://www.youtube.com/watch?v=cgxJHBJ_X-g&feature=related

Ex:

Following is my current document.

开发者_Python百科

http://www.youtube.com/watch?v=cgxJHBJ_X-g&feature=related

I have a User Script and the code is

var doc = document.location.toString();
doc = doc.replace("v=cgxJHBJ_X-g","v=2AGrlGvtLxE");

I am just trying to replace the current document URL with some other URL. But I am getting the following Error.

Uncaught TypeError: Object http://www.youtube.com/watch?v=cgxJHBJ_X-g&feature=related has no method 'replace'


Use document.URL or window.location.href instead of document.location.toString().

Example:

var url = document.URL;
window.location.href = url.replace("v=cgxJHBJ_X-g","v=2AGrlGvtLxE").
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号