0

I've been searching online for an answer to this but I can't seem to find anything which can help.

I was wondering if its possible to open a index.html file with an extension after the .html

(for example it would open a file like this - index.html?lc=uk) automatically when you would double click the file or when you click on a link which connects to that file.

Hope that makes sense.

If anyone could help would be much appreciated.

Regards, Seb

user2072826

 function setGetParameter(paramName, paramValue) { var url = window.location.href; if (url.indexOf(paramName + "=") >= 0) { var prefix = url.substring(0, url.indexOf(paramName)); var suffix = url.substring(url.indexOf(paramName)); suffix = suffix.substring(suffix.indexOf("=") + 1); suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : ""; url = prefix + paramName + "=" + paramValue + suffix; } else { if (url.indexOf("?") < 0) url += "?" + paramName + "=" + paramValue; else url += "&" + paramName + "=" + paramValue; } window.location.href = url; } 

and then in the body tag:

<body onload="setGetParameter('lc', 'uk');"> 

This has worked but the problem is that it keeps refreshing the page constantly. Is there a way to stop the refreshing?

2 Answers 2

1

Unfortunately this does not work. You can not pass URL Parameters into the file-name.

If you want to add it as the page loads, you could add this to the JavaScript of the page:

function setGetParameter(paramName, paramValue) { var url = window.location.href; if(!(url.indexOf(paramName) >= 0)) { if (url.indexOf(paramName + "=") >= 0) { var prefix = url.substring(0, url.indexOf(paramName)); var suffix = url.substring(url.indexOf(paramName)); suffix = suffix.substring(suffix.indexOf("=") + 1); suffix = (suffix.indexOf("&") >= 0) ? suffix.substring(suffix.indexOf("&")) : ""; url = prefix + paramName + "=" + paramValue + suffix; } else { if (url.indexOf("?") < 0) url += "?" + paramName + "=" + paramValue; else url += "&" + paramName + "=" + paramValue; } window.location.href = url; } } 

and then in the body tag:

<body onload="setGetParameter('lc', 'uk');"> 

Original Source(Yes, there is a difference between the code)

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

7 Comments

Hi user2072726, it doesn't seem to have work, I've added the code to the html file but it doesnt seem to change anything when I've opened the file.
Sorry ignore previous comment, I have solved why it wasn't work and its working :) - but the only problem is that it keeps refreshing the page.. Anyway to stop that?
Okay, I added a second piece of code that should prevent the page from reloading. Just replace what I have given you already with the edit.
I've changed it to the new edit but now it doesnt add the extension like the previous code. :(
I've doubled checked everything but it doesnt seem to add the extension to the url :'(
|
0

If you are using Apache, you may use mod_rewrite to perform almost any kind of "magic" with request file names. As long as you know home to use regular ecpressions, of course. I suggest you to do some research on mod_rewrite.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.