简体   繁体   English

JavaScript小书签和URL编码

[英]JavaScript bookmarklet and URL encoding

Fully disclosing that I do not know Javascript, I'm trying to get this Javascript: 完全透露我不知道Javascript,我试图得到这个Javascript:

javascript:location = 'http://validator.w3.org/check?uri=' +escape(location)&doctype=Inline&charset=detect+automatically&ss=1&group=0&user-agent=W3C_Validator/1.654';

to work as a Bookmarklet in order to send a URL of this format: 作为Bookmarklet工作,以发送此格式的URL:

http://validator.w3.org/check?uri=http://www.wordpress.org&charset=%28detect+automatically%29&doctype=Inline&ss=1&group=0&user-agent=W3C_Validator%2F1.654

to the W3C valdiator. 到W3C的指挥官。

I'm URL encoding the Javascript with this encoder , but of course, I'm doing something wrong, either in my Javascript or in the process of encoding it. 我是用这个编码器对Javascript进行URL编码的,但当然,我做错了,无论是在我的Javascript中还是在编码过程中。

Anyone have some ideas in particular or in general about Javascript bookmarklets and URL encoding? 任何人都有一些关于Javascript bookmarklet和URL编码的特别或一般的想法? Thanks. 谢谢。

Two Errors: 两个错误:

  1. You need to access the "href" member of the location object: 您需要访问位置对象的“href”成员:

    window.location. window.location的。 href = http://foo.com href = http://foo.com

  2. You have invalid JavaScript: 您的JavaScript无效:

    javascript:location = ' http://validator.w3.org/check?uri= ' +escape(location) PLUS SIGN AND QUOTE MISSING HERE &doctype=Inline&charset=detect+automatically&ss=1&group=0&user-agent=W3C_Validator/1.654'; javascript:location =' http : //validator.w3.org/check?uri='+ escape(location) PLUS SIGN AND QUOTE MISSING HERE &doctype = inline&charset = detect + automatic&ss = 1&group = 0&user-agent = W3C_Validator / 1.654';

I recommend using this: 我建议使用这个:

javascript:(function(){window.location.href='http://validator.w3.org/check?uri='+escape(window.location.href)+'&doctype=Inline&charset=detect+automatically&ss=1&group=0&user-agent=W3C_Validator/1.654';})()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM