I am trying to embed iframe using javascript but the "referrerpath" variable is not working inside the document.write() I am new to javascript, how to fix it? thanks
var referrerpath = document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '').replace(/\?.*/, '');
document.write("<iframe src='https://example.com/embed/' + referrerpath + style='border:none;width:100%;min-height:400px;'></iframe>");
You can use template literals. You need to use backticks ( ` ) in order to use them.
var referrerpath = document.referrer.replace(/^[^:]+:\/\/[^/]+/, '').replace(/#.*/, '').replace(/\?.*/, '');
document.write(`<iframe src='https://example.com/embed/${referrerpath}' style='border:none;width:100%;min-height:400px;'></iframe>`);
You aren't closing the string before concatenating it with your variable:
"<iframe src='https://example.com/embed/" + referrerpath + "' style='border:none;width:100%;min-height:400px;'></iframe>"
You could also use a template literal
`<iframe src='https://example.com/embed/${referrerpath}' style='border:none;width:100%;min-height:400px;'></iframe>`