URL data passing and JQuery Effect - php

I have the following code in my web app
<li>A</li>
And the javascript function 'next' creates and loads the following link when the above item is clicked:
.../testing.php?first=A#result
It works fine, It calls the 'result' anchor, and I extract the value of 'first' via:
$first=$_GET['first'];
but the problem is, I am using JQuery Mobile and the sliding effect that usually happens between anchor switches doesnt work. It simply loads another page.
I tested out a bunch of different ways of passing the data through the URL, and it seems the slidin g effect only happens when the anchor tag immediately follows the 'testing.php' portion of the url like this:
.../testing.php#result
Is there a way to pass the data in a URL after the anchor tag and extract it with php?
OR
Is there a way to force the sliding effect?
Thanks guys.

If you are loading the new page into the dom via jQM's ajax-handling of links then you can omit the hash portion of the url. When jQM loads the new page into the dom it only load the portion of the page within the data-role="page" element. So if you use a url like:
/testing.php?first=A
and testing.php outputs a page like this:
<div data-role="page" id="testing_<?php echo $_GET['first']; ?>">
...
</div>
then the rest of the website can use the id (testing_A) output by testing.php to reference the newly added page.

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>

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

send user back to a particular part of the previous page after functions complete using header?

does anyone know if i can get header in php to take a user to a certain point on a page when a form has been submitted and a function has finished and then it redirects a person back to a certain part of that page?
this is my if result:
$_SESSION['message_sent']="<div class=\"message_sent\"></div>";
header("Location: {$_SERVER['HTTP_REFERER']}");
it currently takes the user back to the page they was on but i want the user to be taken to the middle of the page?
thanks.
try doing as following, take for eg : "test" is the "name" attribute of anchor tag on the page :
HTML CODE :
<a name="test"></a>
<div>
.......
</div>
PHP CODE :
$path = $_SERVER['HTTP_REFERER']."#test";
header("Location:$path");
If you're familiar with having links within a page this should be simple.
You basically have your URL and append the id of the HTML element you want the page to go to when it loads. For example a URL like this:
http://www.mysite.com/index.php#about
Would take you to the following element on the index.php page:
<div id="about"></div>

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

Trying to load a different iframe within a div popup box depending on which of several links is clicked to open the box

I have an overlay popup box (DIV + JavaScript + some CSS) which is toggled by a link, like this:
<a href="#" onclick="popup('popUpDiv')">
The box that pops up contains an iframe. Now I want different links on my page to load different iframes when the box opens; so that link A would toggle the box to appear, and load iframe1.html inside the box, while link B would toggle the same box to appear, but load iframe2.html inside the box, and so forth.
I'm a beginning programmer, and I first figured maybe this could be done with PHP, by putting something like this inside the popUpDiv:
<iframe src="http://mysite.com/iframe<?php echo $_GET ["iframeid"] ?>.html">
... and then simply adding ?iframeid=x to each link's href, where x is the id of the iframe to be loaded.
This obviously won't work in practice though, because it requires a page reload, and when the link is clicked, the popUpDiv is toggled to open, but at the same instant, the page reloads, now with the ?iframeid=x query string in place, but too late, since the popUpDiv disappeared on reload.
Is there perhaps a JavaScript equivalent that could be used, or can anybody suggest another way to make this work?
FYI, this is the kind of popup box I'm working with:
http://www.pat-burt.com/csspopup.html
I finally found a really simple way of accomplishing this without additional JavaScripting, by simply using the target attribute:
<iframe name="myfavoriteiframe">
Then:
This is a link.
P.S. Just FYI for any of those out there who might want to use this feature with Vimeo's JavaScript API, as I'm doing: In order to make API buttons work with this target method, it seems like the iframe src-attribute cannot be left blank. You need to specify a link to any of your videos in the src, so that a video loads into the iframe on page load, like this:
<iframe name="myfavoriteiframe" id="player_1" src="http://player.vimeo.com/video/[the_number_of_your_video]?api=1&player_id=player_1">
I simply inserted the URL to the first video on my page, but you can use any of them, since they're hidden anyway.
Then link to any of your videos using the target method described above, and the pre-set iframe video will be replaced by a video of your choice.
Create two divs with the two variations of content (the two iframes with each specific URL). Then toggle by the name of the div.
<a href="#" onclick="popup('popUpDiv1')">
<a href="#" onclick="popup('popUpDiv2')">
Set the id attributes of the div elements appropriately.
Rather than adding something to the popup DIV element, I would add a required link to the href property of the link that you use to open the popup:
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
<a href="http://example.com/first/uri" onclick="pre_popup('popUpDiv')">
And then inside the popup function I would take the href parameter of the link that has triggered the event and use it in a popup:
function pre_popup(id) {
// Take the href parameter of the link
var href = this.href;
// And then use it in the iframe
window.frames["your_iframe"].src = href;
// And then pop it
popup(id);
}

Categories