Okay, I am developing a web application using MVC 4 and I want to display Ads from Chitika. I don't want these ad's to be blocked by the client side. I was wondering if it is possible to have the javascript for the chitika ads on a static html page.
<div class="ads">
<script type="text/javascript">
ch_client = "";
ch_width = 728;
ch_height = 90;
ch_type = "";
ch_sid = "";
ch_color_site_link = "0000CC";
ch_color_title = "0000CC";
ch_color_border = "F4F1E6";
ch_color_text = "000000";
ch_color_bg = "F4F1E6";
</script>
<script src="http://scripts.chitika.net/eminimalls/amm.js" type="text/javascript">
</script>
</div>
And then call the page like so:
var Request = (HttpWebRequest)WebRequest.Create("/adsstatic.html");
var adResult = (HttpWebResponse)Request.GetResponse();
Stream receiveStream = adResult.GetResponseStream();
StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8);
return readStream.ToString();
and then display the returned html on the view? Is this totally stupid?
Thanks
Related
What I am trying to achieve
I am trying to load a cookie from Website A in the background as a 1 x 1 pixel followed by redirecting users to Website B.
Problem
In the code below, users are redirected to Website B. However, it does not appear that Website A was loading in the background as I could not see the Website A cookie in the browser.
How can I solve this?
Thank you
<html>
<META name="description" HTTP-EQUIV="Refresh" CONTENT="">
<iframe id="MyFrame" style="width: 1px; height: 1px;"></iframe>
</html>
<script>
document.addEventListener("DOMContentLoaded", function(){
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var tidParameter = urlParams.get("tid");
var offerParameter = urlParams.get("offer");
console.log (offerParameter);
if (offerParameter == "bb") {
var address = "www.websiteA.com/?tid=";
var combined = address + tidParameter;
var iframeSrcValue = document.getElementById("MyFrame").src;
document.getElementById('MyFrame').setAttribute("src", combined);
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=www.websiteB.com");
}
else if (offerParameter == "bd") {
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=https://www.google.com");
}
else {
document.querySelector('meta[name="description"]').setAttribute("content", "5;url=https://www.hotmail.com");
}
});
</script>
What confuses me
When I try the code in this manner, it works (ie. redirects to Website B and cookie from Website A loads). Unclear to me why the addition of the if, else if causes the problem?
<html>
<META HTTP-EQUIV="Refresh" CONTENT="5;url=www.websiteB.com">
<iframe id="MyFrame" style="width: 1px; height: 1px;"></iframe>
</html>
<script>
document.addEventListener("DOMContentLoaded", function(){
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
var mainParameter = urlParams.get('tid');
var address = "www.websiteA.com/?tid=";
var combined = address + mainParameter;
console.log(combined);
var iframeSrcValue = document.getElementById("MyFrame").src;
document.getElementById('MyFrame').setAttribute("src", combined);
});
<script>
I'm setting up some editors with HTML, CSS and JS code. The code of each of them is reloaded in an iframe when it's change. HTML and CSS code reloads perfectly, bus the JS code that is injected inside of a script in the body of the iframe is not working, possible because it's not rerunning once it's updated, but I don't know how to do it...
Any idea?
Here's an example in Plunker http://plnkr.co/edit/tpl:8rFfZljYNl3z1A4LKSL2?p=preview
HTML
<div class="result">
<!-- RESULT -->
<style id="style"></style>
<script id="script"></script>
<script id="jQ" type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<iframe id="view" class="view"></iframe>
</div>
JS
var app = angular.module('plunker', []);app.controller('MainCtrl', function($scope) {
var style = document.getElementById('style');
var script = document.getElementById('script');
var jQ = document.getElementById('jQ');
var view = document.getElementById('view');
var viewDocument = view.contentDocument || view.contentWindow.document;
var body = viewDocument.getElementsByTagName('body')[0];
var head = viewDocument.getElementsByTagName('head')[0];
var widgets = [];
var loadScript = document.createElement('script');
loadScript.innerHTML = "var $ = parent.$; console.log('loaded');";
$scope.html = '<div id="test">Testing</div>';
$scope.js = 'console.log("More test");';
head.appendChild(jQ);
head.appendChild(loadScript);
head.appendChild(style);
body.appendChild(script);
$scope.$watch('html', function(nv){
body.innerHTML = nv;
body.appendChild(script);
});
$scope.$watch('js', function(nv){
script.innerHTML = nv;
});});
Note: Code seems to run fine when is set by hand
SOLVED:
I found a way around. Here's the code in case someone else need it
setTimeout(updatePreview(codeHTML, codeCSS, codeJS), 300);
function updatePreview(codeHTML, codeCSS, codeJS) {
var view = document.getElementById('view');
var viewDocument = view.contentDocument || view.contentWindow.document;
var codeHTML = (codeHTML === undefined) ? '' : codeHTML;
var codeCSS = (codeCSS === undefined) ? '' : codeCSS;
var codeJS = (codeJS === undefined) ? '' : codeJS;
viewDocument.open();
viewDocument.write('<style type="text/css">' + codeCSS + '</style>');
viewDocument.write('<script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>');
viewDocument.write(codeHTML);
viewDocument.write('<script type="text/javascript">' + codeJS + '</script>');
viewDocument.close();
}
This is called in $scope.$watch of de editors passing the updated value.
Weave: http://kodeweave.sourceforge.net/editor/#b6b39c95ec91f42950957a1ac8dc707f
I see you were able to solve your problem however I have a minor suggestion.
If a user uses setTimeout or setInterval like so...
setInterval((function() {
return $('body').css('background', newGradient())
}), 1000)
The problem you have in your code is it will add to the original literation and your setInterval function in this case will be added to the previous one.
Thus a good idea is to create the iframe dynamically and add the code within that. This way you have more control over what's being added to the iFrame and how to handle it.
document.querySelector(".preview").innerHTML = ""
var frame = document.createElement("iframe")
frame.setAttribute("id", "preview")
frame.setAttribute("sandbox", "allow-forms allow-modals allow-pointer-lock allow-popups allow-same-origin allow-scripts")
document.querySelector(".preview").appendChild(frame)
I originally posted this How can I load js into my templates with Meteor/handlebars.js?
and thought I had a solution to my issue. I was wrong. I have some external js I want to load as well as an internal script. I tried placing the scripts in a template alone for example:
<template name="myscripts">
<script src="myexternalscript"></script>
<script src="anotherexternalscript></script>
<script src="anotherexternalscript"></script>
<script>
//internal script code here
</script>
</template>
then on the template with the html I want those scripts to affect, which contains html named "myothertemplate", I added
{{myscripts}}
to the bottom of those elements where I wanted it to load. Then that template which contains the html elements and the {{myscripts}} which I want to load the JavaScript, is loaded on my main page in the body {{>myothertemplate}}. I run my project, localhost:3000 and get no errors. I see the scripts I wanted there on the page where I wanted them as well but they don't work. They have no affect on the page. I tried taking the internal JavaScript and saving it as a JavaScript file as well as the external JavaScript files however this is not working either. This is an example of what I want:
<!--HTML here-->
<!--some elements here
after the last div on this template page, I wanted to add my scripts.-->
<div>
</div>
<script src="some external script"></script>
<script src="some external script"></script>
<!--Now my internal script-->
<script>
(function() {
// Base template
var base_tpl =
"<!doctype html>\n" +
"<html>\n\t" +
"<head>\n\t\t" +
"<meta charset=\"utf-8\">\n\t\t" +
"<title>Test</title>\n\n\t\t\n\t" +
"</head>\n\t" +
"<body>\n\t\n\t" +
"</body>\n" +
"</html>";
var prepareSource = function() {
var html = html_editor.getValue(),
css = css_editor.getValue(),
js = js_editor.getValue(),
src = '';
src = base_tpl.replace('</body>', html + '</body>');
css = '<style>' + css + '</style>';
src = src.replace('</head>', css + '</head>');
js = '<script>' + js + '<\/script>';
src = src.replace('</body>', js + '</body>');
return src;
};
var render = function() {
var source = prepareSource();
var iframe = document.querySelector('#output iframe'),
iframe_doc = iframe.contentDocument;
iframe_doc.open();
iframe_doc.write(source);
iframe_doc.close();
};
var cm_opt = {
mode: 'text/html',
gutter: true,
lineNumbers: true,
};
var html_box = document.querySelector('#html textarea');
var html_editor = CodeMirror.fromTextArea(html_box, cm_opt);
html_editor.on('change', function (inst, changes) {
render();
});
cm_opt.mode = 'css';
var css_box = document.querySelector('#css textarea');
var css_editor = CodeMirror.fromTextArea(css_box, cm_opt);
css_editor.on('change', function (inst, changes) {
render();
});
cm_opt.mode = 'javascript';
var js_box = document.querySelector('#js textarea');
var js_editor = CodeMirror.fromTextArea(js_box, cm_opt);
js_editor.on('change', function (inst, changes) {
render();
});
var cms = document.querySelectorAll('.CodeMirror');
for (var i = 0; i < cms.length; i++) {
cms[i].style.position = 'absolute';
cms[i].style.top = '30px';
cms[i].style.bottom = '0';
cms[i].style.left = '0';
cms[i].style.right = '0';
cms[i].style.height = '100%';
}
/*cms = document.querySelectorAll('.CodeMirror-scroll');
for (i = 0; i < cms.length; i++) {
cms[i].style.height = '100%';
}*/
}());
</script>
$.getScript('/myscript.js') worked.
I have a swf file created by EasyPano tourweaver software. the outpout is a swf file with some .bin files to config the swf and other files such as .jpg, .js and so on.
The software create a html file to add the swf but i have to load the swf using flash and AS3. the HTML and JavaScript that the software create is :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mahan</title>
</head>
<body leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0">
<script type="text/javascript" src="swfobject.js"></script>
<div id="flashcontent">
To view virtual tour properly, Flash Player 9.0.28 or later version is needed.
Please download the latest version of Flash Player and install it on your computer.
</div>
<script type="text/javascript">
// <![CDATA[
var so = new SWFObject("twviewer.swf", "sotester", "100%", "100%", "9.0.0", "#000000");
so.addParam("allowNetworking", "all");
so.addParam("allowScriptAccess", "always");
so.addParam("allowFullScreen", "true");
so.addParam("scale", "noscale");
//<!-%% Share Mode %%->
so.addVariable("lwImg", "resources/talarmahan_1_firstpage.jpg");
so.addVariable("lwBgColor", "255,255,255,255");
so.addVariable("lwBarBgColor", "255,232,232,232");
so.addVariable("lwBarColor", "255,153,102,153");
so.addVariable("lwBarBounds", "-156,172,304,8");
so.addVariable("lwlocation", "4");
so.addVariable("lwShowLoadingPercent", "false");
so.addVariable("lwTextColor", "255,0,0,204");
so.addVariable("iniFile", "config_TalarMahan.bin");
so.addVariable("progressType", "0");
so.addVariable("swfFile", "");
so.addVariable("href", location.href);
so.write("flashcontent");
// ]]>
</script>
</body>
</html>
Please Help me!
Thanks
The answer is URLVariables passed to the URLRequest feed into load method of Loader:)
example:
var loader:Loader = new Loader();
var flashvars:URLVariables = new URLVariables()
flashvars["lwImg"] = "resources/talarmahan_1_firstpage.jpg";
flashvars["lwBgColor"] = "255,255,255,255";
flashvars["lwBarBgColor"] = "255,232,232,232";
flashvars["lwBarColor"] = "255,153,102,153";
flashvars["lwBarBounds"] = "-156,172,304,8";
flashvars["lwlocation"] = "4";
flashvars["lwShowLoadingPercent"] = "false";
flashvars["lwTextColor"] = "255,0,0,204";
flashvars["iniFile"] = "config_TalarMahan.bin";
flashvars["progressType"] = "0";
flashvars["swfFile"] = "";
flashvars["href"] = this.loaderInfo.url;
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = flashvars;
loader.load(request);
addChild(loader);
also with following helper method you can get main SWF parameters (from it's html wrapper) and pass it to the loaded SWF:
public function getFlashVars(li:LoaderInfo):URLVariables
{
var vars:URLVariables = new URLVariables();
try
{
var params:Object = li.parameters;
var key:String;
for(key in params)
{
vars[key] = String(params[key]);
}
}
catch(e:Error)
{
}
return vars;
}
then
var loader:Loader = new Loader();
var request:URLRequest = new URLRequest("twviewer.swf");
request.data = getFlashVars(this.loaderInfo);
loader.load(request);
addChild(loader);
For SecurityError: Error#2000 and here - there are many reasons behind this error
I am using a script to load news from different sources, using Google AJAX feed API. How can I get the description of an entry? Below is an hello world program:
<html>
<head>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("feeds", "1");
function initialize() {
var feed = new google.feeds.Feed("http://news.google.com/?output=rss");
feed.load(function(result) {
if (!result.error) {
var container = document.getElementById("feed");
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var div = document.createElement("div");
div.appendChild(document.createTextNode(entry.title));
container.appendChild(div);
}
}
});
}
google.setOnLoadCallback(initialize);
</script>
</head>
<body>
<div id="feed"></div>
</body>
</html>
How can I get the description using the entry object??? I am using the google URL - http://news.google.com/?output=rss for RSS feeds in XML format. I want the "Description" part. How can I get that
You can get the description, but you can't use the JSON format and the entry object to do it. If you read the feed parameters at https://developers.google.com/feed/v1/devguide carefully, you'll see that description is not a field it returns at the entry level - just at the feed level.
To do it, you need to request the feed in XML format, and then load the individual nodes, including description. Here's the relevant snippet I've used to do it - change the formatting etc. as you need.
function initialize() {
var feed = new google.feeds.Feed("http://myblog.com/blog/feed/");
feed.setResultFormat(google.feeds.Feed.XML_FORMAT);
feed.load(function(result) {
if (!result.error) {
var items = result.xmlDocument.getElementsByTagName('item');
item = items[0];
//build each element
var title = document.createElement("h4");
title.innerHTML = item.getElementsByTagName('title')[0].firstChild.nodeValue;
var content = document.createElement("p");
content.innerHTML = item.getElementsByTagName('description')[0].firstChild.nodeValue;
href = item.getElementsByTagName('link')[0].firstChild.nodeValue;
}
The HTML description can be retrieved by using the content variable.
Thus you should have:
div.appendChild(document.createTextNode(entry.content));
Be aware that this will retrieve HTML data format.
After much digging, I found that the Google API uses "contentSnippet" instead of description. No XML formatting needed.
function initialize() {
var feed = new google.feeds.Feed("http://myblog.com/blog/feed/");
feed.setNumEntries(10);
feed.load(function(result) {
if (!result.error) {
$(document).ready(function(){
$('#feed-pull').append('<ul></ul>');
for (var i = 0; i < result.feed.entries.length; i++) {
var entry = result.feed.entries[i];
var desc = entry.contentSnippet;
Change entry.title in:
div.appendChild(document.createTextNode(entry.title));
to entry.description.