0

I have an URL being loaded into a webview, when the loading is complete, I want to get the iframe src that is inside the HTML, and reload the webview with the iframe src.

<iframe frameborder="0" allowtransparency="true" marginheight="0" marginwidth="0" scrolling="no" src="https://example.com/abc"></iframe>

In my iOS code, inside webViewDidFinishLoad , I am trying to get the iframe using

webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('iframe').attr('src')"];

This javascript is working in chrome console, however its not working for me.

Can you please help me?

4

1 回答 1

1

document.getElementById当您实际上在 iframe 上没有id属性时,我很惊讶。试试这个:

document.getElementsByTagName('iframe')[0].src

这是一个在 Safari 中工作的 JSFiddle:

https://jsfiddle.net/5vfv24wu/

于 2016-04-20T04:27:10.927 回答