issue with frames in chrome - javascript

I am facing an issue with frames with this particular code throwing an error:
window.parent.frames["searchoutput"].document.open("text/html");
Error: Uncaught TypeError: cannot call method 'open' of undefined
Any help is highly appreciated.

var frame = window.parent.frames["searchoutput"];
var frameDocument = (frame.contentWindow.document || frame.contentDocument);
frameDocument.open("text/html");
or more comprehensive version to check how to get document:
var doc;
if (iframe.document)
iframe.doc = iframe.document;
else if (iframe.contentDocument)
iframe.doc = iframe.contentDocument;
else if (iframe.contentWindow)
iframe.doc = iframe.contentWindow.document;

Related

Wrote a Google script, it seems that everything is correct, an error occurs

Here is the script:
var sheet_id = "1wA0nalVyJ7ilv2pwS0kIWDoXudlPCTVZvEDPgIYviy4";
var sheet_name = "Start_ESP"
function doGet(e) {
var ss = SpreadsheetApp.openById(sheet_id);
var sheet = ss.getSheetByName(sheet_name);
var date = Number(e.parameter.date);
var sensor = Number(e.parameter.sensor);
sheet.appendRow([sensor, date]);
}
An error occurs on startup:
TypeError: Cannot read properties of undefined (reading 'parameter') doGet # Код.gs:9
I'm new to this, how can I fix this?

Blazor WebbAssembly exception when calling javascript function?

I have a C# function that is invoking a Javascript function, this is the C# function:
await _jsRuntime.InvokeVoidAsync("setMediaUsingStreaming", type, dotnetImageStream);
And this is the Javascript function:
async function setMediaUsingStreaming(fileType, fileStream) {
try {
const arrayBuffer = await fileStream.arrayBuffer();
const blob = new Blob([arrayBuffer]);
const url = URL.createObjectURL(blob);
var newHTMLElement;
var fileHTMLElement = document.getElementById('fileDisplay');
if (fileType == "image") {
newHTMLElement = document.createElement('img');
}
else {
newHTMLElement = document.createElement('video');
var attribute = document.createAttribute('controls');
newHTMLElement.setAttributeNode(attribute);
}
fileHTMLElement.appendChild(newHTMLElement);
newHTMLElement.src = url;
} catch (Exception)
{
console.log(Exception)
}
}
When the C# function is invoking the Javascript function I receive this error :
blazor.webassembly.js:1 Uncaught (in promise) Error:
Microsoft.JSInterop.JSException: Cannot set properties of null
(setting 'src') TypeError: Cannot set properties of null (setting
'src')
The weird thing is that I receive this error when I run the app in publish mode (withouth a debugger) but it works perfectly in debug mode. The catch from the javascript function is not hit when I receive this error, it seems that is the C# method that is throwing it.
I know what the error is saying, that the url variable is null, but I don't understand why is null, and why it works on debug mode.
Do you have any ideas ?

Uncaught TypeError at WebSocket.ws.onmessage

I'm new to web socket and I'm trying to get my feet wet by trying out the code below.
var id=0;
var symbol="";
var interval="";
var open_time=0;
var open=0;
var high=0;
var low=0;
var close=0;
var ws = new WebSocket('wss://stream.bybit.com/realtime');
ws.onopen = function(){
//console.log("Socket has been opened!");
ws.send('{"op":"subscribe","args":["kline.BTCUSD.1m"]}');
}
ws.onmessage = function(msg){
//console.log(msg.data);
var obj = JSON.parse(msg.data);
//console.log(obj.data);
id = obj.data.id;
symbol = obj.data.symbol;
interval = obj.data.interval;
open_time = new Date(obj.data.open_time * 1000);
open = obj.data.open;
high = obj.data.high;
low = obj.data.low;
close = obj.data.close;
}
And although the code above works just fine, but I still can't figure out the error in console log below:
main.js:28 Uncaught TypeError: Cannot read property 'id' of undefined
at WebSocket.ws.onmessage (main.js:28)
I hope somebody can give me an idea why the onmessage function cannot read the property "id" of undefined on the first iteration but no problem reading it on the succeeding loops.
You are getting that error in this statement id = obj.data.id;
Here, you are trying to access id property of data. But data is undefined and that is the reason for that error.
You are getting data from msg, which is sent from a socket connection. Make sure you are sending appropriate msg value the first time.
This is the explanation for that error. If you can post the code where you are sending data to this function, we can find out how to fix that error.
EDIT:
Looks like you are receiving data from some other third-party server. If you can run below code you can see the first message you are receiving.
First message:
{"success":true,"ret_msg":"","conn_id":"b75dcae2-48e6-4283-8922-3799a199d8c8",
"request":{"op":"subscribe","args":["kline.BTCUSD.1m"]}}
As you can see this first message doesn't have data property. And when you try to access it you are getting that error.
data property is present from second message onwards, so you are not getting any error on succeeding messages.
Second message:
{ "topic":"kline.BTCUSD.1m",
"data":{
"id":0,"symbol":"BTCUSD", "open_time":1567828500,"open":10349,
"high":10349.5,"low":10349,"close":10349.5,"volume":420020,
"turnover":40.58444293000001,"interval":"1m"
}
}
Demo:
var ws = new WebSocket('wss://stream.bybit.com/realtime');
ws.onopen = function() {
//console.log("Socket has been opened!");
ws.send('{"op":"subscribe","args":["kline.BTCUSD.1m"]}');
}
messages = [];
ws.onmessage = function(msg) {
messages.push(msg.data);
console.log(messages[0]);
}
You can check if the data property is not undefined or null before accessing it.
ws.onmessage = function(msg) {
if(msg && msg.data) {
var obj = JSON.parse(msg.data);
if(obj && obj.data) {
id = obj.data.id;
symbol = obj.data.symbol;
interval = obj.data.interval;
open_time = new Date(obj.data.open_time * 1000);
open = obj.data.open;
high = obj.data.high;
low = obj.data.low;
close = obj.data.close;
}
}
}

CRM 2015 Microsoft app xpathevaluator' is undefined

We are using crm 2015 and it is working without a problem.
All code is executed correctly in IE and in Chrome.
But when we try to use the crm app from Microsoft we get the error: 'xpathevaluator' is undefined.
I think it is the xrmservicetoolkit that is throwing the error.
if (typeof (node.selectSingleNode) != "undefined") {
return node.selectSingleNode(xpathExpr);
} else {
var xpe = new XPathEvaluator();
var xPathNode = xpe.evaluate(xpathExpr, node, _NSResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
return (xPathNode != null) ? xPathNode.singleNodeValue : null;
}

File API writing file doesn't work Samsung smart tv SDK

I have this javascript code which makes possible writing in a file
{
var fileSystemObj = new FileSystem();
var fileObj = fileSystemObj.openCommonFile(curWidget.id +
‘/testFile.data’, ‘w’);
fileObj.writeLine(‘something to write.’);
fileSystemObj.closeCommonFile(fileObj);
}
but it doesn't work. Doesn't even display any error!
samsung developer forum (you may not see unless you sign in... )
I am quoting it.
case tvKey.KEY_RED:
alert('RED BUTTON!');
alert('CWID: '+curWidget.id);
try {
var fileSystemObj = new FileSystem();
var fileObj = fileSystemObj.openCommonFile(curWidget.id+'/testFile.data','w');
fileObj.writeLine('something to write.');
fileSystemObj.closeCommonFile(fileObj);
} catch (e) {
alert('Error: file handling: '+e);
}
break;
lead to error:
alert() : Error: file handling: TypeError: 'null' is not an object
(evaluating 'fileObj.writeLine')
Reading cause same problem.
and solution accepted in that link is:
I suppose that problem is that you have to create common dir (if does not exist ) at first :
var fileObj = fileSystemObj.openCommonFile(filePath, 'w');
if(!fileObj){
var bValid = fileSystemObj.isValidCommonPath(curWidget.id);
if (!bValid) {
fileSystemObj.createCommonDir(curWidget.id);
}
}
fileObj = fileSystemObj.openCommonFile(filePath, 'w');
fileObj.writeLine('something to write.');
fileSystemObj.closeCommonFile(fileObj);

Categories

Resources