Hello thanks for helping me before. I have a issue and I need its complete solution if someone can help me in this I have a simple php which contains html script and which have iframe included in it. I want its java scrpt embedded code so that users can embed my this script into their pages (php external java script) the script should be like this <script type="text/javascript" src="ip.php"></script> Code (markup): My html code is <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" bgcolor="#FFFFFF"> <tr> <td width="100%"> <iframe width="100%" scrolling="no" height="400" frameborder="0" src="http://localhost/pages/searching" name="I1"></iframe> </td> </tr> <tr> <td width="100%"> <p align="center"><font face="Arial" style="font-size: 6pt"> <a target="_blank" href="http://www.mywebsite.com" style="text-decoration: none"> <font color="#FFFFFF">My Website link</font></a></font></td> </tr> </table> Code (markup): Please provide me the solution
Don't get your point, you want to have users include your script and then display the iframe? then use document.write in your javascript
ok I mean to say that this is my php script and I saved it on my server as mypage.php <?php <html> <body> <table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1" bgcolor="#FFFFFF"> <tr> <td width="100%"> <iframe width="100%" scrolling="no" height="400" frameborder="0" src="http://localhost/pages/searching" name="I1"></iframe> </td> </tr> <tr> <td width="100%"> <p align="center"><font face="Arial" style="font-size: 6pt"> <a target="_blank" href="http://www.mywebsite.com" style="text-decoration: none"> <font color="#FFFFFF">My Website link</font></a></font></td> </tr> </table> </body> </html> ?> Code (markup): Now I want its external javascript code so that my users can us this code to add my page anywhere into their websites using this code <script type="text/javascript" src="http://www.mywebsite.com/mypage.php"></script> Code (markup):
To do that in best way you'll need to make a couple of changes. First, you will most probably want this to be as flexible as possible. For example it would be really nice if you could dynamically( on your server-side) define width and height of the iframe, or bg color... Also, maybe you need to know which user requested this iframe, so that you can customize it further... Best solution will be following: 1. Create php file that will actually render some JavaScript code. Let's call it eric.php : <?php // define as much variables as you need in your remote JS. You can obtain GET variables from global array $_GET $jsResult = array( 'iframe' => array( 'url' => 'http://localhost/test_server/content.php', /* you should change this according to your URL */ 'width' => '200', 'height' => '250', 'passed_id' => $_GET['user_id'] ) ); //form JS from php array Header('content-type: application/x-javascript'); echo 'myCallback( ' . json_encode($jsResult) . ');'; //call some functon after this script is received by the client. ?> Code (markup): Note that you now have full control over JS and actions that should be taken on remote website. 2. Create content.php (this should render content for your iframe): <div style="background: #000; color: #fff;">Hello World!</div> Code (markup): 3. Create some html file to test all this( let's name it index.html) : <html> <head></head> <body> Test website. <script type="text/javascript"> function myCallback(data) { //do whatever you want. This is called after eric.php is loaded myFrame = document.createElement("iframe"); myFrame.setAttribute("src", data.iframe.url); myFrame.style.width = data.iframe.width + "px"; myFrame.style.height = data.iframe.height + "px"; document.body.appendChild(myFrame); //you most probably want to place this in some div or something... } </script> <script type="text/javascript" src="http://localhost/test_server/eric.php?user_id=digitalpoint"></script> </body> </html> Code (markup): I chose to define "myCallback" in this file, but it may be better in your case to define all the required JS inside your eric.php file. To test all this you need to create folder http://localhost/test_server containing files eric.php and content.php. Also create folder http://localhost/remote_site/ and put index.html in it. Have fun!