Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我iframe.get(0).contentWindow.location用来获取 iframe 的当前 url。问题是,如果用户导航离开原始域,则会引发错误。我怎样才能告诉 js/jquery 然后使用iframe.src呢?
iframe.get(0).contentWindow.location
iframe.src
蒂亚!
你需要try得到contentWindow's location:
try
contentWindow
location
try {src = iframe.get(0).contentWindow.location.href;} catch(e) {src = iframe.get(0).src;}