javascript script type text defining - javascript

i saw in a website defining script type tag like this , please can anybody tel me what is that "type="text/javascript+fk-window-onload-executed">, what is this "+fk-window-onload-executed" mean?? and why they are using such type..
when i execute below code, code is not executing but when i remove +fk-window-onload-executed then its working fine
<script type="text/javascript+fk-window-onload-executed"">
(function () {
try {
var Lastclick = true;
var viz = document.createElement('script');
viz.type = 'text/javascript';
viz.async = true;
viz.src = ("https:" == document.location.protocol ?"https://" : "http://localhost")+ "/projects2/857/VIZVRM857.src.js";
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(viz, s);
viz.onload = function () {
try {
pixel.parse(Lastclick)
} catch (i) {}
};
viz.onreadystatechange = function () {
if (viz.readyState == 'complete' || viz.readyState == 'loaded') {
try {
pixel.parse(Lastclick)
} catch (i) {}
}
}
} catch (i) {}
})();</script>
please anybody tell me, why they are using such type definition and what is the benefit of using such type.
Thanks in advance..
Please help

From looking at the source you provided this is a custom document type flip kart is using (fk == Flip Kart). My guess would be they are using it to prevent reloading the script on certain occasions.

Related

unable to trigger window.open on js code

Im having issues with .js codes. the window.open seems to be not working. i have tried using window.location and not working also. Can anyone suggest what could be the fix for this?
Here's the code that im currently using
if ("web page" == $scope.model.ComponentModel.Screen.trnscntype) {
var staffId = ichrisCache.get("loginStaffNumber");
if ($scope.model.ComponentModel.FormCode == 'SEL') {
var menulinkParameters = { staffId: staffId, formCode: $scope.model.ComponentModel.FormCode };
$scope.retLink = "";
var menuLinks = SelfServiceLinkURL.query(menulinkParameters,
function (output) {
$scope.retLink = output;
console.log($scope.retLink);
alert('inside menulinks');
});
alert('outside menulinks');
window.location.href = $scope.retLink;
//window.open("http://www.stackoverflow.com/");
}
else
{
window.open($scope.model.ComponentModel.Screen.urlwebpage);
}
}
although the $scope.retLink can be logged on console.log but when i placed it inside the window.open($scope.retLink); it is not triggering.
Suggestions and inputs are greatly appreciated.
Thanks!

Loading a script with Javascript- doesn't work on chrome?

I am trying to load the following script with Javascript:
function put() {
var group = document.getElementById("obj_0123456790");
var children = group.childNodes;
for( var i = 0; i < children.length; i++ ) {
if( (children[i].name == 'movie') || (children[i].name == '') ) {
children[i].src = "http://website.com/song.swf";
}
}
}
if (window.attachEvent) {
window.attachEvent('onload', put);
} else {
if (window.onload) {
var curronload = window.onload;
var newonload = function() {
curronload();
put();
};
window.onload = newonload;
} else {
window.onload = put;
}
}
I load it with the following code:
<script>
var i=document.createElement('script');
i.src="http://website.com/putter.js";
document.head.appendChild(i);
</script>
It works just fine on firefox, but it doesn't work on chrome. How can I make it work on chrome?
1.This function will work cross-browser for loading scripts asynchronously
function loadScript(src, callback)
{
var s,
r,
t;
r = false;
s = document.createElement('script');
s.type = 'text/javascript';
s.src = src;
s.onload = s.onreadystatechange = function() {
//console.log( this.readyState ); //uncomment this line to see which ready states are called.
if ( !r && (!this.readyState || this.readyState == 'complete') )
{
r = true;
callback();
}
};
t = document.getElementsByTagName('script')[0];
t.parent.insertBefore(s, t);
}
2.If you've already got jQuery on the page, just use
$.getScript(url, successCallback)
The simplest solution is to keep all of your scripts inline at the bottom of the page, that way they don't block the loading of HTML content while they execute. It also avoids the issue of having to asynchronously load each required script.
If you have a particularly fancy interaction that isn't always used that requires a larger script of some sort, it could be useful to avoid loading that particular script until it's needed (lazy loading).
3.Example from Google
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js?onload=onLoadCallback';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
4.You might find this wiki article interesting : http://ajaxpatterns.org/On-Demand_Javascript
5.If its any help take a look at Modernizr. Its a small light weight library that you can asynchronously load your javascript with features that allow you to check if the file is loaded and execute the script in the other you specify.
Here is an example of loading jquery:
Modernizr.load([
{
load: '//ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js',
complete: function () {
if ( !window.jQuery ) {
Modernizr.load('js/libs/jquery-1.6.1.min.js');
}
}
},
{
// This will wait for the fallback to load and
// execute if it needs to.
load: 'needs-jQuery.js'
}
]);

Adding disqus to a meteor.js project

i am trying to add the disqus commentsystem to my application.
I followed the instruction written in this article KLICK
I created a template called disqus.html
<template name="disqus">
{{#isolate}}
<div id="disqus_thread"></div>
<noscript>Please enable JavaScript to view the comments powered by Disqus.</noscript>
comments powered by <span class="logo-disqus">Disqus</span>
{{/isolate}}
</template>
If this template is rendered, embed.js should load once and disqus makes a reset.
Template.disqus.rendered = function() {
Session.set("loadDisqus", true);
return typeof DISQUS !== "undefined" && DISQUS !== null ? DISQUS.reset({
reload: true,
config: function() {}
}) : void 0;
};
React on sessionchange in deps.autorun
Meteor.startup (function () {
Deps.autorun(function() {
if(Session.get("loadDisqus") && !window.DISQUS) {
var disqus_shortname = '<example>'; // required: replace example with your forum shortname
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
}
});
});
This works fine in Firefox 25.0.1. I can login, logout and create comments. But it isnt working in Chrome 31.0.1650.57 m. It is not possible for me to login. No error is thrown.
What can i do? Any suggestions?
Even a login to disqus in discovermeteor.com/... is not possible for me.
Using session here is interesting but unnecessary.
Here is what i migth do in your disqus.js file:
var isDisqusLoaded = false,
myScriptLoader = function funcMyScriptLoader(jsEl, callback) {
if (window.attachEvent) {
// for IE (sometimes it doesn't send loaded event but only complete)
jsEl.onreadystatechange = function funcOnReadyStateChange() {
if (jsEl.readyState === 'complete') {
jsEl.onreadystatechange = "";
} else if (jsEl.readyState === 'loaded') {
jsEl.onreadystatechange = "";
}
if (typeof callback === 'function') {
callback();
}
};
} else {
// most browsers
jsEl.onload = function funcOnLoad () {
if (typeof callback === 'function') {
callback();
}
};
}
};
Template.disqus.rendered = function funcTplDisqusRendered() {
if (!isDisqusLoaded) {
var myElJs = document.createElement('script'),
s = document.getElementsByTagName('script')[0];
myElJs.type = 'text/javascript';
myElJs.async = true;
myElJs.src = '//' + disqus_shortname + '.disqus.com/embed.js';
myScriptLoader(myElJs, function funcEventLoaded() {
isDisqusLoaded = true;
});
s.parentNode.insertBefore(myElJs, s);
}
};
Using that script you won't need to use Deps.autorun and Session.
You should use that kind of feature only where you want to get realtime, but if don't need it, avoid it coz it will degrade your app performance.
You can add Disqus.reset if it's really needed but i'm not sure, look at the disqus documentation.
I didn't test the script but it should be ok.
Sounds like a weird cacheing error, have you tried resetting chrome's cache?

Adding events to detect when all dynamically added scripts are loaded

There are no errors thrown in the code, so I can only assume either the events aren't getting triggered or they aren't getting added properly. Can anyone determine what the issue is here?
Code below. Fiddle here.
$('#fake-body').append('init<br />');
var scriptTag,
scriptsLoaded = 0,
scripts = ['//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js', '//codeorigin.jquery.com/ui/1.9.2/jquery-ui.min.js'],
scriptLoadedCallback = function(val) {
scriptsLoaded++;
$('#fake-body').append('callback called for '+val+' | scriptsloaded = '+scriptsloaded+' & length = '+scripts.length+'<br />');
if(scriptsLoaded === scripts.length) {
$('#fake-body').append('all loaded');
}
};
$.each(scripts, function(index, value) {
$('#fake-body').append('preparing '+value+'<br />');
scriptTag = document.createElement('script');
scriptTag.type = 'text/javascript';
scriptTag.src = value;
if(typeof scriptTag.addEventListener !== 'undefined') {
$('#fake-body').append('add event for good browsers<br />');
scriptTag.addEventListener('load', (function() {
scriptLoadedCallback(value);
}), false);
} else {
$('#fake-body').append('add event for the other one<br />');
scriptTag.attachEvent('onreadystatechange', function() {
if(scriptTag.readyState === 'loaded') {
scriptLoadedCallback(value);
}
});
}
$('#fake-body').append('appending script<br />');
$('#fake-body').append(scriptTag);
});
$('#fake-body').append('complete');
use plain Javascript to load javascript files rather than jquery(because jquery won't fire the load callback in your current code), so replace :
$('#fake-body').append(scriptTag);
with:
$('#fake-body')[0].appendChild(scriptTag);
or if you insist to use jquery, you have to respect the following statements order (or use getScript):
$body.append(scriptTag);
scriptTag.attachEvent
scriptTag.src = scriptUrl;
jsfiddle
you have another error by referencing scriptsloaded rather than scriptsLoaded in the callback.

"Unable to load http://url status:0" error in onbeforeunload-method

may someone of you can help me to find this problem?
I've got an xpage with client-side js-code included which should be executed when you decide to leave the page. In the client-side js you refer to a button and click it automatically. This button got some server-side js code included and change the flag from a document from ("opened by ..." to "").
The thing is that somehow the client-side js did not work in all different browsers except the current IE (10.0.5) and throws the error:
unable to load http://urlofthedocument/... status:0
The funny thing about this is, when I insert an alert()-method right after the click()-method everything works fine in every browser. But as I don't want to include this alert statement I figure out there must be something different to avoid this. (A short pause instead of the alert-method also did not work.)
My CS JS-Code:
window.onbeforeunload = WarnEditMode;
function WarnEditMode(){
if(needUnloadConfirm == true){
var el = window.document.getElementById("#{id:Hidden4SSJS}");
el.click();
//document.open();
//document.write(el);
//document.close();
//alert("You're about to leave the page");
//pause(5000);
}
}
function pause(millis){
var date = new Date();
var curDate = null;
do { curDate = new Date(); }
while(curDate-date < millis)
}
This refers to to button, which executes following SS JS code, after it is clicked:
try{
print("Hidden4SSJS-Button-Test # Person");
var db:NotesDatabase = database;
var agt:NotesAgent;
var doc:NotesDocument = XPPersonDoc.getDocument()
agt = db.getAgent("(XPUnlockDocument)");
agt.run(doc.getNoteID());
}catch(e){
_dump(e);
}
May you guys can help me with this?
I would do this using the XSP object with a hidden computed field (and not your special button)...
Something like this:
function WarnEditMode(){
if(needUnloadConfirm == true){
XSP.partialRefreshGet("#{id:unlockDocCF1}", {
params: {
'$$xspsubmitvalue': 'needToUnlock'
},
onComplete: function () {
alert('You are about to leave this page and the document has been unlocked.');
},
onError : function (e) {
alert('You are about to leave this page and the document has NOT been unlocked.\n' + e);
}
);
}
pause(5000);
}
Then the computed field's javascript would be something like this:
try{
var sval = #Explode(context.getSubmittedValue(), ',');
if (sval == null) return result + " no action.";
if (!"needToUnlock".equals(sval[0])) return result + " no action.";
print("Hidden4SSJS-Button-Test # Person");
var db:NotesDatabase = database;
var agt:NotesAgent;
var doc:NotesDocument = XPPersonDoc.getDocument()
agt = db.getAgent("(XPUnlockDocument)");
agt.run(doc.getNoteID());
return 'document unlocked.';
}catch(e){
_dump(e);
}

Categories

Resources