有没有一种方法可以通过命令行将字符串传递给html javascript?
我是初学者!我需要这样的东西:有没有一种方法可以通过命令行将字符串传递给html javascript?,javascript,html,string,command-line,Javascript,Html,String,Command Line,我是初学者!我需要这样的东西: C:\MyHtmlPage.html "string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage" C:\MyHtmlPage.html?parm=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage 并将“字符串\u需要\u传递\u给\u javascript\u代码\u在\u MyHtmlPage中
C:\MyHtmlPage.html "string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage"
C:\MyHtmlPage.html?parm=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage
并将“字符串\u需要\u传递\u给\u javascript\u代码\u在\u MyHtmlPage中”放入:
有类似的方法吗?
谢谢大家!
编辑:
我找到路了!
在DOS命令行中,我写:
start firefox "file:///C:/MyHtmPage.html?externalstring=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage"
在javascript中,我添加了这个(http://papermashup.com/read-url-get-variables-withjavascript/):
谢谢大家的建议!=) 否,但如果您在浏览器中加载它,则可以使用 像这样:
<a href="file:///C:/MyHtmPage.html#string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage">CLICKY</a>
您可以使用如下查询参数:
C:\MyHtmlPage.html "string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage"
C:\MyHtmlPage.html?parm=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage
然后,在javascript页面中,您可以使用window.location.search
检索parm=xxxx片段,并根据需要解析出xxx。如果需要,此格式允许您传递多个不同的参数。这是将多个参数嵌入URL的通用方法。然后,可以通过页面中的javascript或服务器(如果URL来自web服务器)解析它们
C:\MyHtmlPage.html?parm=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage