I'm using this override to get the content of a js file as a string.
Content of the variable where the js file is loaded into:
<html>
<body>
//META{"name":"testPlugin"}*//
function testPlugin() {
var settings = {
testSettingBool : true,
testSettingInt : 123,
testSettingStr : "Test String",
}
}
testPlugin.prototype.getName = function() { return "Test"; };
testPlugin.prototype.getDescription = function() { return "Test Description"; };
testPlugin.prototype.getVersion = function() { return "1.0"; };
</body>
</html>
Now i only want to eval a special function in that string like
testPlugin.prototype.getVersion();
Thanks for any help :)
Related
I am getting an error when loading JavaScript file to Webview.
[chromium] [INFO:CONSOLE(7)] "Message origin must match parent origin!", source: https://service.force.com/embeddedservice/5.0/eswFrame.min.js (7)
This is my JS file
<html>
<body>
<button onclick="Chat1()">Submit</button>
<script type='text/javascript' src='https://service.force.com/embeddedservice/5.0/esw.min.js'></script>
<script type='text/javascript'>
function Chat1() {
try {
var initESW = function (gslbBaseURL) {
embedded_svc.settings.displayHelpButton = true; //Or false
embedded_svc.settings.language = ''; //For example, enter 'en' or 'en-US'
embedded_svc.settings.enabledFeatures = ['LiveAgent'];
embedded_svc.settings.entryFeature = 'LiveAgent';
console.log("inside initESW- ", gslbBaseURL);
embedded_svc.init(
'https://ulr.my.salesforce.com',
'https:/ulr.force.com/visualforce',
gslbBaseURL,
'00D00055uj',
'US_Universities',
{
'baseLiveAgentContentURL': 'https://c.la3-c1cs-cdg.salesforceliveagent.com/content',
'deploymentId': '5720Q008Oqg',
'buttonId': '5730Q000PID',
'baseLiveAgentURL': 'https://d.la3-c1cs-cdg.salesforceliveagent.com/chat',
'eswLiveAgentDevName': 'EmbeddedServiceLiveAgent_Q00000000jLUAQ_17d9a605e8e',
'isOfflineSupportEnabled': false
}
);
};
if (!window.embedded_svc) {
var s = document.createElement('script');
console.log("Control here1", s);
var MinFile = 'https://ulr.my.salesforce.com/embeddedservice/5.0/esw.min.js/'
console.log("Control here2")
s.src = MinFile;
s.crossOrigin = 'anonymous';
s.onload = function () {
initESW(null);
}
document.body.appendChild(s);
}
else {
initESW('https://service.force.com');
}
}
}
</script>
</body>
</html>
How can I fix this issue ?
For me issue was, I was using html file from Assets folder and assigning content on webview but the data (html+JS) should come from URL and that should rendered on webview.
I have this Razor code:
<script>
app.run(function () {
var key = $('##Model.HtmlId');
key.inputFilter(function (value) {
return new RegExp('#Html.Raw(RegularExpressions.KeyPattern)').test(value);
});
});
</script>
And this is my RegularExpressions class:
public class RegularExpressions
{
public const string KeyPattern = #"^[a-z-]+$";
// other patterns
}
And what I get in my rendered HTML (page source in browser) is this:
<script>
app.run(function () {
var key = $('#key_Key_b13dca0421ac4740b5e177b80c002c25');
key.inputFilter(function (value) {
return new RegExp('^[a-z-]+$').test(value);
});
});
</script>
However, I get this JavaScript error in my browser console:
Uncaught SyntaxError: Invalid or unexpected token
And when I click on it, I see this code:
app.run(function () {
var key = $('#key_Key_5be9a1756c8549199d3b37e0eea35bba');
key.inputFilter(function (value) {
return new RegExp('^[a-z-]+</div>).test(value);
});
});
What is wrong here?
I want to get data from a website, can I get url data from code?
Example code:
<script type="application/json" id="store">
{
"url":{"host":"localhost"},
"resources":
{
"xxfff":
{
"stream":
{
"streamId":"","duration":212714,"videos":
[
{
"url":"www.test.com"
},
{
"url":"www.site.net"
}
]
}
}
},
}
</script>
I just want to get "www.site.net" from script code, is it possible?
This is absolutely possible. To demonstrate, I'm going to show you how you could create such an element in the first place, and then how to retrieve the data. If you are manually putting the code in the script tag, I would suggest stringifying it first.
let src = document.createElement('script');
src.setAttribute('id', 'store');
let json = {
url : {
host : "localhost"
},
resources : {
xxfff : {
stream : {
streamId : "",
duration : 212714,
videos : [
{
url : "www.test.com"
},
{
url : "www.site.net"
}
]
}
}
}
};
json = JSON.stringify(json);
src.innerText = json;
const body = document.getElementsByTagName('body')[0];
const footer = document.getElementById('footer');
body.insertBefore(src, footer);
// Now you have created the element,
// so you reverse the process to get your data
src = document.getElementById('store');
json = src.innerText;
json = JSON.parse(json);
let sites = json.resources.xxfff.stream.videos;
sites.map(site => console.log(site.url));
If you mean you have this script tag somewhere in your webpage, you can read it as any other tag, using innerHTML (right in the first line of this snippet):
var json=document.getElementById("store").innerHTML;
var data=JSON.parse(json);
var videos=data.resources.xxfff.stream.videos;
var table=document.getElementById("tbl");
videos.forEach(function(urlObj){
var td=document.createElement("td");
td.innerHTML=urlObj.url;
var tr=document.createElement("tr");
tr.appendChild(td);
table.appendChild(tr);
});
<script type="application/json" id="store">
{
"url":{"host":"localhost"},
"resources":
{
"xxfff":
{
"stream":
{
"streamId":"","duration":212714,"videos":
[
{
"url":"www.test.com"
},
{
"url":"www.site.net"
}
]
}
}
}
}
</script>
<table border="1" id="tbl"></table>
On a side note, there was a surplus comma in your original post (right before the last closing curly brace) which made the entire thing invalid. I removed it in the hopes of it was just some copy-paste issue, perhaps you had more fields just wanted to cut the post shorter.
Also, if you generate this data immediately into the page, you could just let it be "normal" script, and surround it with a simple var data= and ; pair. Then it would be a variable already, without the need for parsing.
I hope to deliver the value from popup.js to background.js so that I can open the website as what i expect. I use the localStorage variable as my json's value. But when found that the value I have delieverd to background.js in the argument input of the function openTab(input) is always the string "localStorage.input" itself. How can I solve it?
popup.js
window.onload=function()
{
localStorage.input=document.getElementById("search").value;
document.getElementById("submit").onclick=function()
{
chrome.extension.sendMessage({command:"start",input:localStorage.input});
}
}
background.js
chrome.runtime.onMessage.addListener(
function(request,sender,sendResponse)
{
switch(request.command)
{
case "start":
openTab(request.input);
break;
}
return true;
}
);
var openTab=function(input)
{
chrome.windows.create
(
{
url:"http://www.baidu.com/s?wd="+input,
}
);
};
try this out
var lStore = localStorage.input || '';
window.onload=function()
{
var search = document.getElementById("search");
search.value = lStore
document.getElementById("submit").onclick=function()
{
// var input = search.value; //try this as well
var input = lStore;
chrome.extension.sendMessage({command:"start",input:input});
}
}
I'm using Kendo UI Mobile via Icenium Extension for Visual Studio. I'm very new at this, but I'm stumbling along. I've written a method (called popDataSource) in a view that gets some data (reads the names of files in a folder) and returns those file names. The method works perfectly if I wire it up to a button click event, but what I really want is for the method to be called when the page first loads. I've tried setting data-show=popDataSource and even data-after-show=popDataSource, but when I do that I get the error Object [object Object] has no method 'set' when I try to return the data. I'm also not that well versed in javascript, which I'm sure isn't helping me any.
Here's my code:
Snippet from index.html:
<div id="tabstrip-listSonicImages" data-role="view" data-title="Sonic Images List" data-model="app.listSonicImagesService.viewModel"
data-after-show="app.listSonicImagesService.viewModel.popDataSource">
<div data-role="content" class="view-content">
<div data-role="scroller">
<div class="buttonArea">
<a id="btnShowList" data-role="button" data-bind="click: popDataSource"
class="login-button">Display List</a>
</div>
<ul class="forecast-list" data-role="listview" data-bind="source: sonicImagesDataSource" data-template="sonic-image-list-template">
</ul>
</div>
</div>
</div>
<script type="text/x-kendo-tmpl" id="sonic-image-list-template">
<a data-role="listview-link" href="\#tabstrip-playSonicImage?fileName=${fileName}">${fileName}</a>
</script>
listiconimages.js
(function(global) {
var SonicImageListViewModel,
app = global.app = global.app || {};
SonicImageListViewModel = kendo.data.ObservableObject.extend({
popDataSource: function () {
var that = this;
var listSI = new Array();
try{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSys) {
fileSys.root.getDirectory("SIData", { create: true, exclusive: false},
function (dataDirEntry) {
var directoryReader = dataDirEntry.createReader ();
directoryReader.readEntries(
function (entries) {
var rows = entries.length;
for (i = 0; i < rows; i++) {
var fName = entries[i].name;
listSI[i] = { "fileName": fName, "image": "xxx" };
}
},
function (error) {
alert("error: " + error.code);
}
);
},
null);
},
null
);
var dataSource = new kendo.data.DataSource(
{
data: listSI,
filter: { field: "fileName", operator: "endswith", value: ".simg" }
}
);
that.set("sonicImagesDataSource", dataSource);
} catch (ex) {
alert(ex.message);
}
}
});
app.listSonicImagesService = {
viewModel: new SonicImageListViewModel()
};
}
)(window);
app.js
(function (global) {
var mobileSkin = "",
app = global.app = global.app || {};
document.addEventListener("deviceready", function () {
app.application = new kendo.mobile.Application(document.body, { layout: "tabstrip-layout" });
}, false);
app.changeSkin = function (e) {
if (e.sender.element.text() === "Flat") {
e.sender.element.text("Native");
mobileSkin = "flat";
}
else {
e.sender.element.text("Flat");
mobileSkin = "";
}
app.application.skin(mobileSkin);
};
})(window)
As I said, I'm new to Icenium and Kendo, and my javascript knowledge is limited, so I'm not quite sure where the answer lies. Any help would be greatly appreciated.
Thanks