为了找到如何根据iframe的网址在控制台中将变量仅定义为数字“ 1214693”的方法,我尝试了“文档”。但是我几乎从不使用html或javascript,所以我真的不确定该怎么做。



<iframe src="/build/upload?groupId=1214693" id="upload-iframe" frameBorder="0" scrolling="no" style="width:100%; height:175px; margin-left:10px"></iframe>

最佳答案

它在window对象中,而不在document中。

在iframe .html中使用以下代码:

console.log(window.location.href)


它将记录URL。

然后,简单地处理令牌化URL并提取数据:



// thanks to http://stackoverflow.com/questions/11582512/how-to-get-url-parameters-with-javascript/11582513#11582513
function getURLParameter(name) {
  return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null
}
if (window.console) {
  var idParam = getURLParameter('id');
  console.log(idParam);
}

10-05 20:38
查看更多