jquery - Load external javascript file and create iframe -
this question has answer here:
i need create javascript return iframe tag. customer paste script in iframe need be, , script should create iframe.
must this:
<script src="http://www.helloworld.com/script/loadcustomerframe.js" data-customer="14532"></script> then script should load iframe url somewhere, , need read "data-customer".
i backend developer c#, not frontend. have try several days now, cant work.
please help. thanks
something should work:
$(document).ready(() => { $("[data-customer]").each(function() { let customerid = $(this).data("customer"); $(this).replacewith(`<p>this customer #${customerid}.</p>`); // following comment example of how use iframe //$(this).replacewith(`<iframe src="http://example.org/customer/${customerid}>hello!</iframe>`); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div data-customer="1"></div> <div data-customer="2"></div> <div data-customer="3"></div> you'll need have script appear once (most in <head>) , replace <div> has data-customer attribute. need figure out proper url <iframe>.
Comments
Post a Comment