我正在使用 iframe.get(0).contentWindow.location
来获取 iframe 的当前 url。问题是,如果用户导航离开原始域,则会引发错误。我如何告诉 js/jquery 使用 iframe.src
代替?
TIA!
最佳答案
您需要尝试
获取contentWindow
的位置
:
try {src = iframe.get(0).contentWindow.location.href;}
catch(e) {src = iframe.get(0).src;}
关于javascript - 在 iframe.src 和 iframe.contentwindow.location 之间进行选择的函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17146099/