Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

Here is code suggested from similar question (How to get the value from URL Parameter?)

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;
} ();
share|improve this answer
 
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? –  FlyezTV Jun 19 at 19:29
add comment

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;
share|improve this answer
 
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? –  FlyezTV Jun 19 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... –  Alex Wayne Jun 19 at 19:37
 
But it doesnt work check out that webpage it contains a videostream, it can not change with your method –  FlyezTV Jun 19 at 19:48
 
You want to change the URL of the page you are on? Oh, that was totally not clear... See my edit. –  Alex Wayne Jun 19 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 –  FlyezTV Jun 19 at 20:33
show 2 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.