'iframe that updates html

I am trying to build an iframe that reacts to the URL that is being inputted.

For example if the user goes to: domainA.com/somethingnice then the iframe src should be sub.domainB.com/somethingnice so basically always following the path.

I also plan to use javascript to hide the frame src - something like this:

<script type="text/javascript"> 
$(document).ready(function(e) { 
  $('iframe').attr('src','https://sub.domainB.com/'); 
}); 
</script> 
 
<body> 
<iframe src="" /> 
</body> 

But I have no clue even where to start in making that src to change based on the user's links or inputs.

Any ideas are really welcome!

BTW: the src should NOT change if the users click anywhere inside the iframe - it should act just like a normal wesbite. Only when they follow an external (or direct) link to that subdomain the src for the iframe should be rewritten

Thank you!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source