0

Looking to find how to define a variable to only the numbers "1214693" in console based on the url withing the iframe, I've tried "document." but I almost never use html nor javascript so I'm really unsure of how to go about this.

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

2 Answers2

1

It's in the window object, not document.

Use this code in your iframe .html:

console.log(window.location.href)

and it will log the URL.

Then it is a simple matter to tokenize URL and extract data:

// 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);
}
nothingisnecessary
  • 6,099
  • 36
  • 60
0

Not sure if this is what you're looking for but if you'd like the change the URL and have the id be parameterized then you'll want to do something like this:

<script type="text/javascript">
var id = 1214693;
$(document).ready(function() {
$('#iframe').attr('src', '/build/upload?groupId=' + id);
})
</script>
Blake
  • 641
  • 6
  • 12