只是想在一個HTML鏈接像這樣的可變參數:添加HTML URL參數的JavaScript
mywebpage.com/something.html?width=(Parameter1)&height=(Parameter2)
但在該網頁的內容,我想補充一點:
<script>fid="example"; width=(Parameter1); height=(Parameter2);</script>
我該怎麼做只用javascript和Html
只是想在一個HTML鏈接像這樣的可變參數:添加HTML URL參數的JavaScript
mywebpage.com/something.html?width=(Parameter1)&height=(Parameter2)
但在該網頁的內容,我想補充一點:
<script>fid="example"; width=(Parameter1); height=(Parameter2);</script>
我該怎麼做只用javascript和Html
這裏是代碼建議來自類似的問題(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;
}();
這麼長的變量列表有點固定,數量少,保持簡單。
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;
,或更新您是在頁面的網址,只需設置window.location.href
var width = 100;
var height = 100;
var url = "http://mywebpage.com/page.html?width=" + width + "&height=" + height;
window.location.href = url;
我想是這樣的HTTP: //www.redzer.tv/canal1.php?width=350&height=200但是在html中,當你改變url中的寬度值時,看看那個url,它會改變th視頻流內容的寬度,有沒有辦法在HTML和JavaScript中做到這一點? – FlyezTV