简体   繁体   中英

Copy text into iframe - JS

I have this roadblock for some time that I am unable to solve, though it feels like a relatively simple thing to do.

I am trying to pre-fill a form field with a string of text that is on the page. But the form is in an Iframe which is making it difficult.

Here is the page in question however you will not get much out of the link as the dynamic content for you will be empty. This screenshot might explain better: http://prntscr.com/kbqoak

It would grab the text from the "webinartitle" class and insert into form field ( http://prntscr.com/kbqqp4 ).

I fellow user helped me to write up the javascript needed:

$(function(){
$('iframe').contents().find('.refer_webinar input').val($('.webinartitle').text());
});

As instructed I've placed this outside the iframe but the value is still not getting there unfortunately. Here is 2 screenshots that explain the situation: prntscr.com/kbtp4u / prntscr.com/kbtper

Any ideas what I am doing wrong here? Why is it not working?

Thank you in advance for any advice you can give!

Unfortunately, it is impossible for a document to communicate with a sandboxed document within itself AKA an iframe's contents.

You can't apply jQuery to other domain iframes. It's blocked due to security reasons.

Check this out for more of an explanation.

https://en.wikipedia.org/wiki/Same-origin_policy

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM