Skip to content

Commit

Permalink
fixing browser warning after hitting back button on tracker POST requ…
Browse files Browse the repository at this point in the history
…ests.

refactoring iframe generation to better handle IE.
  • Loading branch information
padams committed Apr 2, 2012
1 parent 8faaba8 commit ad126d4
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 25 deletions.
12 changes: 11 additions & 1 deletion log.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@
$owa->e->debug('Logging Event from Url...');
// log event
$ret = $owa->logEventFromUrl();
echo owa_coreAPI::displayView(array(), 'base.pixel');

$r = owa_coreAPI::requestContainerSingleton();
$rt = $r->getRequestType();

if ($rt === 'post') {
owa_lib::redirectBrowser( owa_coreAPI::getSetting('base', 'main_url').'/blank.php');
} else {
echo owa_coreAPI::displayView(array(), 'base.pixel');
}


} else {
// unload owa
$owa->restInPeace();
Expand Down
2 changes: 1 addition & 1 deletion modules/base/css/owa.reporting-css-combined.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* OWA owa.reporting-css package file created Sat, 31 Mar 12 14:33:58 -0400 */
/* OWA owa.reporting-css package file created Sun, 01 Apr 12 19:48:05 -0400 */

/* Start of jqueryui */

Expand Down
7 changes: 7 additions & 0 deletions modules/base/js/owa.js
Original file line number Diff line number Diff line change
Expand Up @@ -1874,6 +1874,13 @@ OWA.util = {
partA.push(partB);
return partA;
}
},

isIE: function() {

if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
return true;
}
}

};
4 changes: 2 additions & 2 deletions modules/base/js/owa.reporting-combined-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions modules/base/js/owa.tracker-combined-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

81 changes: 65 additions & 16 deletions modules/base/js/owa.tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,19 @@ OWA.tracker.prototype = {
*/
generateHiddenIframe: function ( parentElement, data ) {

// Create the iframe which will be returned
var iframe = document.createElement("iframe");
var iframe_name = 'owa-tracker-post-iframe';
var iframe_name = 'owa-tracker-post-iframe';

if ( OWA.util.isIE() ) {
var iframe = document.createElement('<iframe name="' + iframe_name + '" scr="about:blank" width="1" height="1"></iframe>');
} else {
var iframe = document.createElement("iframe");
iframe.setAttribute('name', iframe_name);
iframe.setAttribute('src', 'about:blank');
iframe.setAttribute('width', 1);
iframe.setAttribute('height', 1);
}

iframe.setAttribute('class', iframe_name);
//iframe.setAttribute('name', iframe_name);
iframe.setAttribute('width', 1);
iframe.setAttribute('height', 1);
iframe.setAttribute('style', 'border: none;');
//iframe.onload = function () { this.postFromIframe( data );};

Expand Down Expand Up @@ -1120,22 +1126,31 @@ OWA.tracker.prototype = {
var post_url = this.getLoggerEndpoint();
var doc = this.getIframeDocument(ifr);
// create form
var frm = doc.createElement('form');
var form_name = 'post_form' + Math.random();
//var frm = this.createPostForm();
var form_name = 'post_form' + Math.random();

// cannot set the name of an element using setAttribute
if ( OWA.util.isIE() ) {
var frm = doc.createElement('<form name="' + form_name + '"></form>');
} else {
var frm = doc.createElement('form');
frm.setAttribute( 'name', form_name );
}

frm.setAttribute( 'id', form_name );
frm.setAttribute( 'name', form_name );
frm.setAttribute("action", post_url);
frm.setAttribute("method", "POST");

// create hidden inputs, add them to form
for ( param in data ) {

if (data.hasOwnProperty(param)) {

var input = document.createElement( "input" );
input.setAttribute( "name",param );
input.setAttribute( "value", data[ param ] );
input.setAttribute( "type","hidden");
var input = this.createHiddenFormField( param, data[param] );
//var input = document.createElement( "input" );
//var input = document.createElement( '<input name="' + param + '">' );
//input.setAttribute( "name",param );
//input.setAttribute( "value", data[ param ] );
//input.setAttribute( "type","hidden");
frm.appendChild( input );
}
}
Expand All @@ -1147,8 +1162,42 @@ OWA.tracker.prototype = {
// remove the form from iframe to clean things up
doc.body.removeChild( frm );


},

createPostForm : function () {

var post_url = this.getLoggerEndpoint();
var form_name = 'post_form' + Math.random();

// cannot set the name of an element using setAttribute
if ( OWA.util.isIE() ) {
var frm = doc.createElement('<form name="' + form_name + '"></form>');
} else {
var frm = doc.createElement('form');
frm.setAttribute( 'name', form_name );
}

frm.setAttribute( 'id', form_name );
frm.setAttribute("action", post_url);
frm.setAttribute("method", "POST");

return frm;
},

createHiddenFormField : function( name, value ) {

// cannot set the name of an element using setAttribute
if ( OWA.util.isIE() ) {
var input = document.createElement( '<input name="' + name + '">' );
} else {
var input = document.createElement( "input" );
input.setAttribute( "name",name );
}

input.setAttribute( "value", value );
input.setAttribute( "type","hidden");

return input;
},

getIframeDocument: function ( iframe ) {
Expand Down
5 changes: 5 additions & 0 deletions owa_requestContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,11 @@ public function getCurrentUrl() {
return $this->current_url;
}

public function getRequestType() {

return $this->request_type;
}

}

?>

0 comments on commit ad126d4

Please sign in to comment.