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?

1 Answer 1

1

I'm surprised document.getElementById works when you don't actually have an id attribute on the iframe. Try this instead:

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

Here is a JSFiddle that works in Safari:

https://jsfiddle.net/5vfv24wu/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.