inmobi javascript call ad twice - javascript

According to inmobi Developer Wiki
http://developer.inmobi.com/wiki/index.php?title=JavaScript
You can call the Ads on Demand using manual: true parameter in the Var section:
E.g:
<script type="text/javascript" src="http://cf.cdn.inmobi.com/ad/inmobi.js">
</script>
<script type="text/javascript">
var inmobi_conf = {
siteid : "your site id",
slot : "slot number",
test: true,
manual: true
};
</script>
<div id="adArea"> </div>
To generate the Ad you have to call it using:
_inmobi.getNewAd(document.getElementById('adArea'));
it should populate the Ad.
I´ve created a simple test example to request an Ad on demand (using test siteid provided by inmobi).
The problem is that I have to click twice to load the Ad
Full Source:
<html>
<head>
<script>
var inmobi_conf = {
siteid : "4028cba631d63df10131e1d3191d00cb",
slot : "15",
test: true,
manual: true
};
function loadAdd(){
_inmobi.getNewAd(document.getElementById('screen'));
};
</script>
<script src="http://cf.cdn.inmobi.com/ad/inmobi.js"></script>
</head>
<body>
<div id="screen"> </div>
<button id="btn1" onClick="loadAdd()">Load Ad</button>
</body>
</html>
You can try it out on http://jsfiddle.net/YYzqA/
1st click on "Load Ad" button (no Ad)
2nd click on "Load Ab" button (the Ad will be loaded)
By chance do you know the reasons for this behavior? am I missing something?

You have set manual: true
you need to set it to manual: false for it to automatically set the configuration for you.
When you set manual: true, your first click is loading the configurations
Checkout the fiddle

Related

ASP.NET Master pages <script> not runing

I have a page with multiple Updatepannel that are all visible false and I show them one after another when you click a button.
I want to use bootstrap datetime picker but my problem is that the script is not rune by the browser.
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
});
</script>
If I run this in the console all is working.
Any ideas on how to force the run of the script ?
As requested :
$(function () {
$('#datetimepicker1').datetimepicker();
});
init[1]0: documentcontext: documentURL: "http://localhost:52261/Dashboard.aspx"activeElement: bodyalinkColor: ""all: HTMLAllCollection[520]anchors: HTMLCollection[0]applets: HTMLCollection[0]baseURI: "http://localhost:52261/Dashboard.aspx"bgColor: ""body: bodycharacterSet: "UTF-8"charset: "UTF-8"childElementCount: 1childNodes: NodeList[2]children: HTMLCollection[1]compatMode: "CSS1Compat"contentType: "text/html"cookie: ""cphNavigation_imgProfile: undefinedcurrentScript: nulldefaultView: WindowdesignMode: "off"dir: ""doctype: <!DOCTYPE html>documentElement: htmldocumentURI: "http://localhost:52261/Dashboard.aspx"domain: "localhost"embeds: HTMLCollection[0]fgColor: ""firstChild: <!DOCTYPE html>firstElementChild: htmlfonts: FontFaceSetforms: HTMLCollection[1]head: headhidden: falseimages: HTMLCollection[1]implementation: DOMImplementationinputEncoding: "UTF-8"isConnected: truejQuery19107336506808681962: 1lastChild: htmllastElementChild: htmllastModified: "02/17/2017 11:51:13"linkColor: ""links: HTMLCollection[68]location: LocationnextSibling: nullnodeName: "#document"nodeType: 9nodeValue: nullonabort: nullonauxclick: nullonbeforecopy: nullonbeforecut: nullonbeforepaste: nullonblur: nulloncancel: nulloncanplay: nulloncanplaythrough: nullonchange: nullonclick: nullonclose: nulloncontextmenu: nulloncopy: nulloncuechange: nulloncut: nullondblclick: nullondrag: nullondragend: nullondragenter: nullondragleave: nullondragover: nullondragstart: nullondrop: nullondurationchange: nullonemptied: nullonended: nullonerror: nullonfocus: nulloninput: nulloninvalid: nullonkeydown: nullonkeypress: nullonkeyup: nullonload: nullonloadeddata: nullonloadedmetadata: nullonloadstart: nullonmousedown: nullonmouseenter: nullonmouseleave: nullonmousemove: nullonmouseout: nullonmouseover: nullonmouseup: nullonmousewheel: nullonpaste: nullonpause: nullonplay: nullonplaying: nullonpointercancel: nullonpointerdown: nullonpointerenter: nullonpointerleave: nullonpointerlockchange: nullonpointerlockerror: nullonpointermove: nullonpointerout: nullonpointerover: nullonpointerup: nullonprogress: nullonratechange: nullonreadystatechange: nullonreset: nullonresize: nullonscroll: nullonsearch: nullonseeked: nullonseeking: nullonselect: nullonselectionchange: nullonselectstart: nullonshow: nullonstalled: nullonsubmit: nullonsuspend: nullontimeupdate: nullontoggle: nullonvolumechange: nullonwaiting: nullonwebkitfullscreenchange: nullonwebkitfullscreenerror: nullonwheel: nullorigin: "http://localhost:52261"ownerDocument: nullparentElement: nullparentNode: nullplugins: HTMLCollection[0]pointerLockElement: nullpreferredStylesheetSet: nullpreviousSibling: nullreadyState: "complete"referrer: "http://localhost:52261/Default.aspx"rootElement: nullscripts: HTMLCollection[18]scrollingElement: bodyselectedStylesheetSet: nullstyleSheets: StyleSheetListtextContent: nulltitle: "Credit Hire Portal"visibilityState: "visible"vlinkColor: ""webkitCurrentFullScreenElement: nullwebkitFullscreenElement: nullwebkitFullscreenEnabled: truewebkitHidden: falsewebkitIsFullScreen: falsewebkitVisibilityState: "visible"xmlEncoding: nullxmlStandalone: falsexmlVersion: null__proto__: HTMLDocumentlength: 1__proto__: Object[0]
Update 1
In the master page I have 2 contentplaceholders, one for navigation bar and the second for a multi step form (in here i have the datetimepicker).
If I put the datetimepicker on the navigation content all is working ... :(
You need to insure that your script under the all the declaration of all the .js(Library files).
Ex.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datetimepicker/4.17.45/js/bootstrap-datetimepicker.min.js"></script>
<script src="Link of other.js"></script>
<script type="text/javascript">
$(function () {
$('#datetimepicker1').datetimepicker();
});
</script>
also you can see the error of script in console window of your browser.
ex. in chrome browser press F12. and click on console. it will display the error of your script.

javascript module not being found

I have a bunch of web pages where I have an identical construct:
<html>
<head>
<script src="sorttable.js"></script>
<noscript>
<meta http-equiv="refresh" content="60">
</noscript>
<script type="text/javascript">
<!--
var sURL = unescape(window.location.pathname);
function doLoad()
{
setTimeout( "parent.frames['header_frame'].document.submitform.submit()", 60*1000 );
}
function refresh()
{
window.location.href = sURL;
}
//-->
</script>
<script type="text/javascript">
<!--
function refresh()
{
window.location.replace( sURL );
}
//-->
</script>
<script type="text/javascript">
<!--
function refresh()
{
window.location.reload( true );
}
//-->
</script>
</head>
<body>
.
.
.
<script type="text/javascript">
window.onload = function() { sorttable.innerSortFunction.apply(document.getElementById("OpenFace-2"), []); doLoad(); }
</script>
</body>
</html>
This works perfectly in every page except for one, where when the onload function runs it cannot find the sorttable code (which is loaded from sorttable.js up at the top). All these pages are part of the same application and are all in the same dir along with the js file. I do no get any errors in the apache log or the js console until that page loads, when I get:
sorttable.innerSortFunction is undefined
I can't see what makes this one page different. Can anyone see what is wrong here, or give me some pointers on how I can debug this further?
The code I pasted in is from the source of the page where it does not work, but it is identical as the pages where it does work.
Looks like on that page the table with id OpenPhace-2 by which you try to sort have no needed class: sortable
The function innerSortFunction of sorttable object will be present only if there is any table with sortable class exists.

inmobi javascript return empty banner

I want to get a test ad banner from inmobi. According to inmobi Developer Wiki
http://developer.inmobi.com/wiki/index.php?title=JavaScript
this script
<script type="text/javascript">
var inmobi_conf = {
siteid : "4028cba631d63df10131e1d3191d00cb",
slot : "15",
test: "true"
};
</script><script type="text/javascript" src="http://cf.cdn.inmobi.com/ad/inmobi.js"></script>
must return test banner 320x50, but it always returns an empty banner.
Please help. What am I doing wrong?
You're getting "No-Fill Response". From that link you provided:
For example, if a publisher faces an NFR (No-Fill Response) scenario,
a callback is sent notifying that there is an NFR. The publisher can
now take steps to address and blank real estate issue that was caused
by non-availability of ads.
<div id="my-ad-slot">
<script type="text/javascript">
var inmobi_conf = {
siteid : "your site id",
slot : "slot number",
test: true,
onError : function(code) {
if(code == "nfr") {
document.getElementById("my-ad-slot").style.display = "none";
// do something else. call to other ad network or logic to display in-house ads, etc.
}
}
};
</script>
<script type="text/javascript" src="http://cf.cdn.inmobi.com/ad/inmobi.js"></script>
</div>
In the above code example, the parameter code will give nfr when no ads are returned.

Splitting up a Javascript snippet

The recommendation of the open source web analysis software Piwik is to put the following code at the end of the pages you want to track, directly before the closing </body> tag:
<html>
<head>
[...]
</head>
<body>
[...]
<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.example.com/" : "http://piwik.example.com/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 4);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://piwik.example.com/piwik.php?idsite=4" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->
</body>
</html>
Under the following assumptions:
https is never used
we don't care that the page loads slower because the script is loaded before the DOM
is it okay to convert the above to the following:
HTML file:
<html>
<head>
[...]
<script src="http://piwik.example.com/piwik.js" type="text/javascript"></script>
</head>
<body>
[...]
<noscript><p><img src="http://piwik.example.com/piwik.php?idsite=4" style="border:0" alt="" /></p></noscript>
</body>
</html>
Custom Javascript file with jQuery:
$(document).ready(function() {
try {
var piwikTracker = Piwik.getTracker("http://piwik.example.com/piwik.php", 4);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
}
catch(err) {
}
}
Are there any differences?
You are deferring the tracking until the page is fully loaded. Inline Javascript is executed when the browser finds it, so you'll have different number of visits depending on where you call piwikTracker.trackPageView();. The latter you call it, the lesser number of visits/actions will be counted.
Now, what do you consider a visit/action? If a user click on a link on your page, before the page fully loads, do you consider it a visit?

Why Some Sites not opening in Pop Window?

I have an html page. On that page I want to open popup window. I have a link on which I have to click & open new pop up. But, it is not a new browser window. It is AJAX based popup.
I do have used Queness popup & YUI dialog popup.
Now, in that window I want to show an iframe which will display page related to link I have clicked. But, for security point of view, iFrame is not showing that page on popup window, but the control of the page transfers to that page & page gets redirected to that page.
How to make popup steady to show that window ?
Here, I am showing YUI dialog code :
<html>
<head>
<title>Yahoo Dialog !</title>
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/fonts/fonts-min.css" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/button/assets/skins/sam/button.css" />
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/container/assets/skins/sam/container.css" />
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/connection/connection-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/element/element-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/button/button-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/container/container-min.js"></script>
<script type="text/javascript">
document.documentElement.className = "yui-pe";
</script>
<style type="text/css">
#example {
height:30em;
}
label {
display:block;
float:left;
width:45%;
clear:left;
}
.clear {
clear:both;
}
#resp {
margin:10px;
padding:5px;
border:1px solid #ccc;
background:#fff;
}
#resp li {
font-family:monospace
}
.yui-pe .yui-pe-content {
display:none;
}
</style>
<script>
YAHOO.namespace("example.container");
YAHOO.util.Event.onDOMReady(function () {
// Define various event handlers for Dialog
var handleSubmit = function() {
this.submit();
};
var handleCancel = function() {
this.cancel();
};
var handleSuccess = function(o) {
var response = o.responseText;
response = response.split("<!")[0];
document.getElementById("resp").innerHTML = response;
};
var handleFailure = function(o) {
alert("Submission failed: " + o.status);
};
// Remove progressively enhanced content class, just before creating the module
YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");
// Instantiate the Dialog
YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1",
{ width : "60em",
fixedcenter : true,
visible : false,
constraintoviewport : true,
buttons : [ { text:"Submit", handler:handleSubmit, isDefault:true },
{ text:"Cancel", handler:handleCancel } ]
});
// Validate the entries in the form to require that both first and last name are entered
YAHOO.example.container.dialog1.validate = function() {
var data = this.getData();
if (data.firstname == "" || data.lastname == "") {
alert("Please enter your first and last names.");
return false;
} else {
return true;
}
};
// Wire up the success and failure handlers
YAHOO.example.container.dialog1.callback = { success: handleSuccess,
failure: handleFailure };
// Render the Dialog
YAHOO.example.container.dialog1.render();
YAHOO.util.Event.addListener("show", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
//YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
});
</script>
</head>
<body class="yui-skin-sam">
<h1>Dialog Quickstart Example</h1>
<div class="exampleIntro">
<p>The Dialog Control is designed to allow you to retrieve information from the user and make use of that information within the page — whether interally to the page or by sending the information to the server via form post or XMLHttpRequest. This example shows how to do the latter. Click the button to show the Dialog instance and its form fields; fill out the form; submit the form. Dialog will automatically use the YUI Connection Manager to send the data via XMLHttpRequest to the server and will then echo that data back to you on the page.</p>
</div>
<div>
Yahoo Mail !
</div>
<form >
<div id="dialog1" class="yui-pe-content">
<div class="hd">Please enter your information</div>
<div class="bd">
<form method="POST" action="http://developer.yahoo.com/yui/examples/container/assets/post.php">
<div><p class="whitetext">YMail !<br/>
<iframe src ="http://www.stackoverflow.com/" width="750" height="400"><p>Ymail</p></iframe>
</p></div>
</form>
</div>
</div>
</form>
</body>
</html>
This is dialog.html page. But,while loading it, it will transfer to http://stackoverflow.com.
You can change this url from src property of iframe.
You can only do an XMLHTTP request to a page in the same domain. The browser doesn't allow cross domain requests.
To do a cross domain request you need a server page in your domain that can work as a proxy and do the request for you.
Plenty of page authors do not wish their sites to be displayed in frames on other people's sites and take steps to avoid it.
You need to bite the bullet, accept their wishes, and stop trying to frame third party content without permission.

Categories

Resources