PHP link two buttons together - php

I have a iFrame inside an php page.
The iFrame contains form (in asp), can I link a button outside the iFrame to the button outside?
Thanks!

you can use a button on main page to click a button on iframe page using jquery.
for example in main page if you have:
Main page HTML Sample:
<button id="parentbutton">click me</button>
<iframe name='select_frame' src='http://www.barzegari.com/DEAFULT.ASP'></iframe>
JQUERY in main page:
$("#parentbutton").click(function(){
$('input:button[name=save]').click(function() {
$('iframe[name=select_frame]').contents().find('#mybuttonid').click();
});
});
in iframe html:
you have a button with id(clientid) like "mybuttonid";

this is prevent by cross domain privacy, but you can do it by this way,
in your php page, use file_get_contents to get asp content, filter get form script and paste to php page, by this way, you can do everything as you want :)

Accessing iframe content from other URL will give you the error Refused to display 'YOUR_URL' in a frame because it set 'X-Frame-Options' to 'sameorigin'. This is because, all the server restricts the access of iframe content from third party website for security purpose. If you are not getting the above error, try the below code in your PHP file.
$("#phpbutton").click(function(){
var iframe = $('#aspiframe').contents();
iframe.find("#aspbutton").click();
});
<iframe id='aspiframe' src='YOUR_ASP_URL'></iframe>
<input type="button" id="phpbutton">click here</button>
Note : Make sure you have replaced with correct IDs.

Related

Redirection to a php page via html href tag

i have this button which is on one page and when user clicks on it, it is supposed to redirect to the page mentioned.
<div id="backicon"><img src="com/resources/images/backicon.png"></div>
href is supposed to work with the php and it should redirect to the default_home page, but nothing happens on click. i believe i am missing a thing or two about php code inside html tag?
i also tried
Back
but of no use, any help?
This returns the PSF:urlFor, but doesn't echo it. Try it like so:
<div id="backicon"><img src="com/resources/images/backicon.png"></div>

transfer variable between frames

The questions similar to that I found a lot but still can not realize what I need. I have a page.php that loaded in the block din_content with function .load
Page.php
<div id="ess">
<div id="top_ch">
<h1>Ess</h1>
</div>
<div id="ch">
<iframe name="users" width="220" height="510" align="left" src='ess/users.php' id="userch"></iframe>
<iframe name="text" width="450" height="405" src='ess/text.php'></iframe>
</div>
In page I have two Iframes. So I have two problems. First in main page where that iframes loaded I have Jquery function
$(document).on('click','.link_pro',function () {
//some actions
});
How to make that that function also worked in iframe?
Second, In the first Iframe I have two links. So what I need is that depend of what link you click on, the variable 'active' changed and depend on the value of that variable changed the second iframe. In example, you click on the first link and variable 'active' =1 than it transfered to the second iframe (may be even transfer to the parent and try to send to the second iframe trough method Get) where depend of the value displayed a requested result. I try to realize it with jquery and php. But still didn't get the result. The most problem to get a result from clicking on links in the first Iframe.
If you own the iframes sources and they belong to the same domain as the top window, then, for attaching events, you could probably do something like:
jQuery("iframe").load(function(){
jQuery(this).contents().find(".link_pro").on("click", function(){
});
});
The code above will attach the click event to your iframe's content (.link_pro).
Then, for the second question, if you have, for example, in your top window:
var myTopVar; //This belongs to top window scope
From your iframe, you can access:
top.myTopVar;
I think that should be it but, again, both your top window and iframe should share the same domain (document.domain). If not, you will face same origin policy problems.

Get HTML of an iframe loaded via ajax (please note that iframe is containing a webpage that needs javascript to load) [duplicate]

This question already has answers here:
How to access the content of an iframe with jQuery?
(3 answers)
Closed 9 years ago.
Is it possible to get HTML of an iframe (please note that iframe is refering to a webpage that loads via ajax call) from the page where I am loading it via ajax call using jquery?
Actualy I want to scrap the content of this website.
The issue is that this website loads via ajax. So I can not use curl for getting contents of a web page that require javascript to load.
For the solution of this issue I am calling a php file with ajax from index.php and passing my query q=blog to the php page that returns this iframe to index.php
<iframe id="myframe" src="https://blekko.com/#?q=blog" width="100%" height="100%"></iframe>
After successful ajax response I am saving the response of ajax that is an
iframe refering to the website along with query
in a div in index.php
<div id="myhtml" style="display:none"></div>
After 3 to 6 seconds contents of this website load in the iframe of index.php
I have a jquery function in index.php that checks html of div id "myhtml" after 5 seconds of interval
<javascript>
var newInt = setInterval(function(){ check(); }, 5000);
function check(){
blekko_html = $("#myframe").contents().find("html").html();
alert(blekko_html);
}
</javascript>
But each time when check() function calls, it returns / alert this
<iframe id="myframe" src="https://blekko.com/#?q=blog" width="100%" height="100%"></iframe>
Even if the iframe is loaded with the content of webpage it always returns above iframe's html initialization, not the html of the webpage inside it.
Is it possible to get the html of iframe that is loading via ajax call and that iframe is containing a webpage that loads via ajax call?
if I able to get the html of that iframe then I will send it again to a php page using ajax were I can do scraping and fetch required data.
You are trying to access content of iframe which points to webpage from another domain.
You cannot access content of iframe if the src of that iframe is not pointing to the domain on which your current parent page is. This is called cross domain policy
You will have to use server side language that will grab the html of given url and return it to your index page to display in any div or whatever.
Let me give you an example to explain why javascript cannot have cross domain access.
Suppose i have FB like box on my website inside an iframe
now whenever any user comes on my website i will trigger a click to
the like box which is inside the iframe of like box.
This way my FB page will have lakhs of likes.
But because of cross domain policy this cannot be done.
hope you got my point
you need to make sure the iframe content is loaded first
function check(){
$("#myframe").load(function(){
blekko_html = $("#myframe").contents().find("html").html();
alert(blekko_html);
});
}
maybe add onload to the iframe and check there
like
<iframe id="myframe" src="https://blekko.com/#?q=blog" width="100%" height="100%" onload="check();"></iframe>
and I would modify the check() to do console.log(blekko_html) instead of alert,
then check in developer console in Chrome or in Firebug or in IE F12

PHP/Javascript Bypass user input to display div

I have a page where if you click on a link, it exposes a div that using ajax displays content from a dbase.
After a user edits this content on the server, I'd like to use PHP to return the user to that page. This is no problem using a redirect
header("location:page.php")
However, when the user comes back to the page, ideally, I'd like to have the content in the div open automatically so the user can immediately see edits without having to find the link to open the div and click on it.
Is this possible, either with something in the url to fire the javascript or alternaively, when you load the page with a certain parameter, triggering javascript to open the div.
The code to open the div is a simple javascript call:
View Content
showDiv just uses ajax to display something from the server using responsetext.
Thanks for any suggestions
header("location:page.php?show=1")
Then in page.php body tag:
<body <?php if($_GET['show']==1) { ?>onload="showDiv()"<?php } ?>>

How can I redirect a url that I am pointed to after clicking submit?

There is a html form I have which submits to a Servlet once Submit button is clicked. After the submission the Servlet redirects to a fixed url which is
http://siteforServlets.com/Servlet/Servlet
That site then displays an xml report shown below:
Sorry I cannot post Images not enough rep so I uploaded direct link here:
http://img836.imageshack.us/img836/3343/sitea.png
I dont want my users getting confused seeing an xml I prefer it going blank page or redirecting to a different url...
How can I redirect the url to hide this xml report url?
Mark, I tried what you said but it redirects before the form even loads. Here is a quick jsfiddle I made to demonstrate your suggestion: jsfiddle.net/ujsEG/12/
You could try making the form target a hidden iframe and then set the onload attribute of the iframe with a javascript call to window.location.href.
<script type="text/javascript">
var okToRedirect = false;
function redirect() {
if (okToRedirect) {
window.location.href = 'path/to/new/location';
}
}
</script>
<form action="...some action..." target="MyIframe" onsubmit="okToRedirect = true;">
...
</form>
<iframe name="MyIframe" style="display: none;" onload="parent.redirect()"></iframe>
When the form posts, the results will display inside the hidden iframe. Once the iframe finishes loading, the onload attribute will fire the javascript to redirect the user.
Update
I updated my answer because of your comment. I added a javascript method which the iframe can call. There is now a global variable which is set to false initially. This will prevent the first load of the page from redirecting. When the form posts, the onsubmit event on the form will set the global variable okToRedirect to true, the iframe will reload and will call the redirect() method. This time around, the redirect will occur.

Categories