hi guys i use This HTML code to display my banners, i want use JavaScript’s code instead of HTML but how?
<iframe src="http://example.com/show?width=468&height=120"></iframe>
hi guys i use This HTML code to display my banners, i want use JavaScript’s code instead of HTML but how?
<iframe src="http://example.com/show?width=468&height=120"></iframe>
Are you wanting to use JavaScript to insert the iframe code in to an existing page?
maybe it can help me please tell me
Hi there zanyar_hasani,
what, exactly, is the content of the iframe element?
coothead
no only
<iframe src="http://example.com/show?width=468&height=120"></iframe>
because i get banner from php page with this html code
Yes, that much is understood.
Are you wanting JavaScript to insert the iframe element into the DOM instead of coding it into the HTML?
As coothead asked, knowing exactly what the content is could make a big difference in what the solution is.
No, not no only.
What is the exact content here…
<iframe src=". . . . . . . . . . . . . ."></iframe>
coothead
by this code i display the banner
what is wrong?
i only insert this code in html page and it display banner
<iframe src="http://zeryan.com/show?width=468&height=120"></iframe>
i get the banner size with get method and display random banner with this size ,
its work correctly but i do not want use HTML i want use JavaScript
You could use an XMLHttpRequest to load the content into your page. In its most basic form, that would look like
var req = new XMLHttpRequest();
req.onload = function() {
document.getElementById('container-element').innerHTML = this.responseText;
}
req.open('GET', 'http://example.com/show');
req.send();
However, the content would not be isolated as it is within an iframe, i.e. your styles might interfere with the banner styles and vice versa. Also, it most probably won’t work when the banner is not on the same domain.
x-post…
This…
http://zeryan.com/show?width=468&height=120
…gives a 404 Not Found.
Please give the correct address.
coothead
excuse me the real link was :
http://zeryan.ir/showbanner/show?width=468&height=120
I can’t be sure what that link is supposed to have as HTML because that link returns a page with error messages.
Off-Topic
It is almost always a bad idea to display error messages on a live site.
I don’t know if any of that information could be used by those with mal intent, but IMHO on a live site you should send error messages to a log file, not display them on a page,
Anyway, it looks like the iframe is intended to display a linked image,
Correct?
yes,please help me i can not solve it
Probably the easiest way would be to have the “show” file return JSON to be used by JavaScript instead of HTML to be used in an iframe.
eg.
JavaScript sends image_width
and image_height
to “show”
“show” returns a JSON object something like
{ "site_link" : "example.com",
"image_path" : "example.com/picture.png" }
I guess the first step would be to get “show” to return the information you need based on the width and height arguments passed to it.
Where does the information come from, a database?
please write complete code to get information and send back information
i give all information from database
Errm, there seems to some misunderstanding.
I am not here to find work, compensated or otherwise.
I have no problem helping others to troubleshoot or learn, which I do as my time allows, when I think I might have something to offer and of my own volition.
If you want someone to write code for you, please go somewhere else (the SitePoint forum is not a “job” site) and hire a developer.
If on the other hand you would like to write the code yourself, are willing to learn and have the time. please put together a minimal code example returning a JSON object from a database query as best you can and explain any problems you are having with the code,
i donnot want a complete code i want to see if you want do it with php and javascript or with json how to write it to check my codes that where is my wrong
If it were me I would likely do it using PHP something like
<div class="banner">
<?php echo show_banner("468", "120"); ?>
</div>
But as you posted this in JavaScript and asked how to convert an iframe to JavaScript I thought you were wanting a JavaScript solution (eg. which would be needed for “rotating” content without the need for page reloads).
ok i know how to display with php .the question is : how can show this banners in other host with javascript?
AFAIK, you can’t.
There are cross-site security restrictions that limit what can be done.
You can control what your site does and how it does it. But when it comes to other sites you need to play along or not play at all.