2

I'm a beginner! I need something like this:

C:\MyHtmlPage.html "string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage"

and put the "string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage" inside:

var externalstring

Is there something similar to do that? Thank you!

EDIT:

I found the way! Inside DOS command line I write:

start firefox "file:///C:/MyHtmPage.html?externalstring=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage"

And in javascript I add this (http://papermashup.com/read-url-get-variables-withjavascript/):

var externalstring = getUrlVars()["externalstring"];
alert(externalstring);

function getUrlVars() {
 var vars = {};
 var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, 
 function(m,key,value) {
     vars[key] = value;
 });
 return vars;
}

Thank you all for advices! =)

0

2 Answers 2

2

You can use a query parameter like this:

C:\MyHtmlPage.html?parm=string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage

Then, in your page javascript, you can use window.location.search to retrieve the parm=xxxx piece and parse out the xxx if you want. This format allows you to pass multiple different parameters if you want. This is the generic way that you embed multiple parameters into a URL. They can then be parsed out by either javascript in the page or by the server if the URL comes from a web server.

Sign up to request clarification or add additional context in comments.

Comments

1

No, but if you are loading it in a browser you can use a fragment identifier

Like this:

<a href="file:///C:/MyHtmPage.html#string_that_I_need_to_pass_to_the_javascript_code_inside_MyHtmlPage">CLICKY</a>

and then in javascript:

console.log(window.location.hash);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.