<!DOCTYPE html> <html> <head> <title>Demo Page</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> <script type="text/javascript" src="javascript.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>Demo Page</h1> </div><!-- /header --> <div data-role="content"> <!-- this is a regular page call--> <a href="another-page.html" data-role="button">Another Page</a> <!-- the functionality for this page is defined in "javascript.js" --> <!-- we put it in a data attribute to avoid spiders spidering the link and hammering the device --> <a href="#" id="perform-function" data-role="button" data-link="http://deviceip/index.htm?cmd=xxxx">Perform Function</a> </div><!-- /content --> </div><!-- /page --> </body> </html>another-page.html:
<!DOCTYPE html> <html> <head> <title>Another Page</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.css" /> <script type="text/javascript" src="http://code.jquery.com/jquery-1.6.4.min.js"></script> <script type="text/javascript" src="http://code.jquery.com/mobile/1.0/jquery.mobile-1.0.min.js"></script> </head> <body> <div data-role="page" data-add-back-btn="true"> <div data-role="header"> <h1>Another Page</h1> </div><!-- /header --> <div data-role="content"> <p>This is another page, dude.</p> </div><!-- /content --> </div><!-- /page --> </body> </html>javascript.js:
$(document).ready(function(){
$('#perform-function').bind('click', function(){
// we're storing the link in an attribute
// called 'data-link':
var url = $(this).attr('data-link');
// create iframe if not there, comment display none to see it
if ($('#temp-iframe').length === 0) {
$('<iframe />').attr({
id: 'temp-iframe',
name: 'temp-iframe',
height: 50,
width: 50
}).css({
display: 'none',
position: 'absolute',
left: '50%',
bottom: 0
}).bind('load', function(){
alert('The non-page loaded');
}).appendTo('body');
}
// call the url into the iframe
$('#temp-iframe').attr('src', url);
// jquerymobile already does this because the link is just "#"
// but if you end up
return false;
});
});
posted by Blazecock Pileon at 7:44 AM on December 17, 2011 [1 favorite]