Get current URL from IFRAME

前端 未结 7 1559
小鲜肉
小鲜肉 2020-11-22 08:08

Is there a simple way to get the current URL from an iframe?

The viewer would going through multiple sites. I\'m guessing I would be using something in javascript.<

7条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 08:47

    I had an issue with blob url hrefs. So, with a reference to the iframe, I just produced an url from the iframe's src attribute:

        const iframeReference = document.getElementById("iframe_id");
        const iframeUrl = iframeReference ? new URL(iframeReference.src) : undefined;
        if (iframeUrl) {
            console.log("Voila: " + iframeUrl);
        } else {
            console.warn("iframe with id iframe_id not found");
        }
    

提交回复
热议问题