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>

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>

Please provide me the solution

Recommended Answers

All 15 Replies

Can you write this question more clearly? It looks like your trying to include a PHP file through the <script> tags...

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>
?>

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>

something like this

<?php
header("content-type: application/x-javascript");
echo "document.write('<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=%22http:/localhost/pages/searching/%22 name=\"I1\"></iframe></td></tr><tr><td width=\"100%\"><p align=\"center\"><font face=\"Arial\" style=\"font-size: 6pt\">
<a target=\"_blank\" href=%22http:/www.mywebsite.com/%22 style=\"text-decoration: none\"><font color=\"#FFFFFF\">My Website link</font></a></font></td></tr></table>');";
?>

you include a php file using a javascript include tag? now that's weird man, php include() and require() are used in php to include files. so nevertheless what's the problem? what do you want to achieve?

Why wouldn't you just get the user to add an IFrame to their page??

No I dont want to give iframe only I want to give them a js script code to use script on their web please provide me the solution

I don't see why you are using PHP at all here.

How about they just insert a javascript file?

They insert:

<script src="http://yoursite.com/mypage.js">

then in mypage.js:

<script>
document.write('<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=%22http:/localhost/pages/searching/%22 name=\"I1\"></iframe></td></tr><tr><td width=\"100%\"><p align=\"center\"><font face=\"Arial\" style=\"font-size: 6pt\">
<a target=\"_blank\" href=%22http:/www.mywebsite.com/%22 style=\"text-decoration: none\"><font color=\"#FFFFFF\">My Website link</font></a></font></td></tr></table>');

</script>

PS: I copied the document.write function wholesale from hallianonline's helpful post, just removed the PHP echo. :P

In my page.js you don't need the <script> tags

then how can I use it? please tell me the solution

Put the script that was between the script tags in your .js file. That's it. Don't forget wherever you include that js file is where that table will appear

In my page.js you don't need the <script> tags

the mypage.js is already a javascript file so you don't need the <script> tags. you can go ahead and write your code directly without this tag

Right ok.

So you include the file:

<script type="text/javascript" src="filename.js"></script>

Contents of the included file (I've called it filename.js)

document.write('<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=%22http:/localhost/pages/searching/%22 name=\"I1\"></iframe></td></tr><tr><td width=\"100%\"><p align=\"center\"><font face=\"Arial\" style=\"font-size: 6pt\">
<a target=\"_blank\" href=%22http:/www.mywebsite.com/%22 style=\"text-decoration: none\"><font color=\"#FFFFFF\">My Website link</font></a></font></td></tr></table>');

That's it - wherever you include the file using <script type="text/javascript" src="filename.js"></script> is where that table will be inserted. So if you include that script between the <HEAD> tags it won't be displayed (I don't think)

Yep, exactly.

Then once you get to this point, we'll deal with the fact that your embedded iFrame (within the table) is probably not going to work the way you want it to lol :)


Right ok.

So you include the file:

<script type="text/javascript" src="filename.js"></script>

Contents of the included file (I've called it filename.js)

document.write('<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=%22http:/localhost/pages/searching/%22 name=\"I1\"></iframe></td></tr><tr><td width=\"100%\"><p align=\"center\"><font face=\"Arial\" style=\"font-size: 6pt\">
<a target=\"_blank\" href=%22http:/www.mywebsite.com/%22 style=\"text-decoration: none\"><font color=\"#FFFFFF\">My Website link</font></a></font></td></tr></table>');

That's it - wherever you include the file using <script type="text/javascript" src="filename.js"></script> is where that table will be inserted. So if you include that script between the <HEAD> tags it won't be displayed (I don't think)

so you just want to include your iframe on every page? well you don't have to use PHP to do that, a simple javascript can do the work

<html>
<head>
<script type="text/javascript" src="test2.js"></script> 
</head>
<body>
</body>
</html>

test2.js

document.write("<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://www.w3schools.com/' 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.w3schools.com/' style='text-decoration: none'><font color='#FFFFFF'>My Website link</font></a></font></td></tr></table>");

replace the sample url(i use w3schools :D) on the iframe's src and on anchor's href attribute with your own url

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.