0

Just want a variable parameter in an html url like this:

mywebpage.com/something.html?width=(Parameter1)&height=(Parameter2)

But in the content of that webpage i want to add this:

<script>fid="example"; width=(Parameter1); height=(Parameter2);</script>

How can i do it using only javascript and Html

2 Answers 2

0

Here is code suggested from similar question (How to get the value from the GET parameters?)

var QueryString = function () {
  // This function is anonymous, is executed immediately and 
  // the return value is assigned to QueryString!
  var query_string = {};
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
        // If first entry with this name
    if (typeof query_string[pair[0]] === "undefined") {
      query_string[pair[0]] = pair[1];
        // If second entry with this name
    } else if (typeof query_string[pair[0]] === "string") {
      var arr = [ query_string[pair[0]], pair[1] ];
      query_string[pair[0]] = arr;
        // If third or later entry with this name
    } else {
      query_string[pair[0]].push(pair[1]);
    }
  } 
    return query_string;
} ();
1
  • I want something like this redzer.tv/canal1.php?width=350&height=200 but in html, look at that url when you change the width value in the url, it changes the width of the videostream content, Is there a way to do that in HTML and javascript? Commented Jun 19, 2013 at 19:29
-1

So long the list of variables is somewhat fixed and small in quantity, keep it simple.

HTML:

<a href="#" id="some-link-id>Click me!</a>

JS:

var width = 100;
var height = 100;

var link  = document.getElementById('some-link-id');
var url   = "http://mywebpage.com/page.html?width=" + width + "&height=" + height;
link.href = url;

Or to update the URL of the page you are on, simply set window.location.href

var width = 100;
var height = 100;

var url = "http://mywebpage.com/page.html?width=" + width + "&height=" + height;
window.location.href = url;
7
  • I want something like this redzer.tv/canal1.php?width=350&height=200 but in html, look at that url when you change the width value in the url, it changes the width of the videostream content, Is there a way to do that in HTML and javascript? Commented Jun 19, 2013 at 19:27
  • Yes there is. It is my answer. That's why it has HTML and JS in it. So I don't understand your question... Commented Jun 19, 2013 at 19:37
  • But it doesnt work check out that webpage it contains a videostream, it can not change with your method Commented Jun 19, 2013 at 19:48
  • You want to change the URL of the page you are on? Oh, that was totally not clear... See my edit. Commented Jun 19, 2013 at 19:51
  • Yes look how it changes, compare: redzer.tv/canal1.php?width=350&height=200 and redzer.tv/canal1.php?width=720&height=480 Thats made with php but i wanna do that with html and javascript Commented Jun 19, 2013 at 20:33

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.