[英]pass parameter to next page with javascript
javascript將auot生成一些照片和照片的描述。 我需要點擊照片,然后它會將參數(標題)發送到下一頁,所以讓下一頁生成我點擊的照片的信息庫
這是我的代碼,我嘗試使用document.submit()來做它但似乎失敗了。
在第一頁:
function print(){
var detail = getVideo();
var number = detail.length;
document.getElementById("watch").innerHTML = "";
for (i=0;i<=number;i++){
document.getElementById("watch").innerHTML += ('<a href="play.html" onclick="submitvideo(detail[i].title)"><img src='+detail[i].poster+'></a>');
document.getElementById("watch").innerHTML += ('<h class="vname">'+detail[i].title+'</h>')
document.getElementById("watch").innerHTML += ('<p>'+detail[i].desc+'</p>');
}
function submitvideo(title){
title.submit();
}
在第二頁:(現在只是用來測試它是否通過)
<script type="text/javascript">
function getv(){
alert(document.location.search);
}
</script>
使用href作為參數持有者href="play.html?title='+detail[i].title+'"
function print(){
var detail = getVideo();
var number = detail.length;
document.getElementById("watch").innerHTML = "";
for (i=0;i<=number;i++){
document.getElementById("watch").innerHTML += ('<a href="play.html?title='+detail[i].title+'"><img src='+detail[i].poster+'></a>');
document.getElementById("watch").innerHTML += ('<h class="vname">'+detail[i].title+'</h>')
document.getElementById("watch").innerHTML += ('<p>'+detail[i].desc+'</p>');
}
在play.html
您可以拆分鏈接並獲取photoTitle
var fullUrl = window.location.href;
var titlePhoto = fullUrl.split("title=")[1];
console.log(titlePhoto)
像這樣改變你的代碼
document.getElementById("watch").innerHTML += ('<a href="play.html?title='+detail[i].title+'"><img src='+detail[i].poster+'></a>');
如果頁面來自同一個域和協議, 本地存儲可以幫助您嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.