error when i try to obtain content of an iframe using javascript code as shown - google-chrome-extension

I have an iframe within the main window named "test_iframe".
I want to access the content of "test_iframe" within a google chrome extension.
I am trying to access the content of this iframe, but I am getting the following error-
Uncaught TypeError: Cannot read property 'contentWindow' of null
The javascript code I have used is given below-
var htmlvar = document.getElementById('test_iframe').contentWindow.document.body.innerHTML;
What is wrong with the code? How can I make it work?

instead of test_iframe in coding try folllwing
<%=txtName.ClientID%>
i.e.
var htmlvar = document.getElementById('<%=txtName.ClientID%').contentWindow.document.body.innerHTML;

Related

JS code to move link location in custom policy doesn't work in azure b2c

I have to move my forgot password link, I used all steps for enabling javascript in my signin&signup custom policy like explained in this documentation.
My JS code is (it works in local html page not in azure) :
<script type="text/javascript" data-preload="true">
window.onload = function moveLinks() {
alert("Test!!");
/* Password Link*/
v_div = document.createElement("div");
v_div.setAttribute("id","divPass");
var passLink = document.getElementById("forgotPassword");
v_div.appendChild(passLink);
next.parentNode.insertBefore(v_div, next.nextSibling);
}
</script>
when I inspect the page I see my js code in the head, no error is detected, the alert does not appear and I do not understand where the error comes from!!
Can someone help please?
• The error is coming because your syntax is invalid because it seems you are trying to use an inline tag as a javascript element since it is throwing an unexpected token error but tags don’t work the same way they work in HTML as they still must follow javascript syntax, so they can’t contain arbitrary javascript code since you are modifying B2C page layout in custom policy code.
Thus, I would suggest you omit the tag and do the following. Below is just a sample reference: -
‘ import {javascript} from ‘<name of the referencing HTML file>’;
window.onload = function moveLinks() {
alert("Test!!");
/* Password Link*/
v_div = document.createElement("div");
v_div.setAttribute("id","divPass");
var passLink = document.getElementById("forgotPassword");
v_div.appendChild(passLink);
next.parentNode.insertBefore(v_div, next.nextSibling);
}
export passLink;
Hence, by using the ‘import’ parameter, the javascript code can be rectified successfully. Also, please refer to the links below for more clarity on the code modification and compilation: -
https://github.com/eslint/eslint/issues/10628
https://developer.salesforce.com/forums/?id=9062I000000IKXYQA4
Also, please refer to the link below for more details on customizing the B2C UI: -
https://moviesdiag132.blob.core.windows.net/b2c/global.css

How to write an html from a remote function using writeDump or writeOutput?

I am coming from Adobe Coldfusion and I'm trying to debug a component in Lucee by writing values to the output. Normally what I do is:
component Sample {
remote Void function spotCheck() {
writeDump(1234);
writeOutput("<br>Test");
return
}
Then hit the page to HTTP://localhost/sample/Sample.cfc?method=spotCheck
But it does not work. I updated the function to have a returnformat="text", but then the output is plain text with HTML tags in its text form. I tried setting it to "html" instead of text but then I get the error below:
This page contains the following errors:
error on line 20 at column 17: xmlParseEntityRef: no name
Below is a rendering of the page up to the first error.
I'm probably doing it the wrong way and I'm happy to learn the Lucee way of how to easily inspect values of variables inside a component function.
PS: I don't have/use step by step debugger.

How to navigate Edge extension local storage callback requirements

I'm trying to access the local storage data in Edge set by my options page, using my popup script. Is there a current, working example of this available?
I was using localStorage, but it would only update the popup if I reloaded the extension after saving changes in my options page. I want to make it easier on the user by allowing the popup to access it immediately after saving, without reloading. I found the browser.storage.local.get(), but documentation conflicts everywhere I look, and I can't find viable working examples.
I have used, per Edge documentation:
browser.storage.local.get("sample");
But it throws an error requiring a callback function. So then I used:
let sample = browser.storage.local.get("example");
sample.then(ifGood, ifBad);
I get an error regarding property "then".
Then I simply tried adding a callback to the action itself:
sample = browser.storage.local.get("example", callbackFunction);
function callbackFunction(data){
alert(data);
}
The end alert should display a string, but it just displays an empty Object. How do I access the data returned in the callback? I tried callbackFunction(this) as an argument in the get, but it throws an error about the syntax of the get.
I found a work-around using browser.runtime.reload() in the Options page when saving the changes. It still reloads the extension, but it does it without requiring the user to do it manually.
You should use this syntax:
browser.storage.local.get(propertyName | null, callbackFn)
where
callbackFn = function fn(resultObject) {...}
When you pass null you will get whole storage object.
Look for example 1 or example 2 in my Edge extension.

Using canvas drawImage in chrome extension content script

I'm trying to use drawImage on Canvas Context in injected content script from my Chrome Extension.
testCanvas = document.createElement('canvas');
testContext = testCanvas.getContext('2d');
var image = new Image();
testContext.drawImage(image, 0, 0);
In Chrome 26 it works ok, but in dev channel (Chrome 28) this seams broken as I got this message:
Uncaught TypeError: Type error
When I move same script directly into background page, it works without any problem.
I think this can be related to some security related change but I failed to find any relevant information.
This is a bug, you should report it. Some more testing reveals that in Chrome 28.0.1498.0, the Image constructor does not create a valid HTMLImageElement instance (as seen in the screenshot below).
This code is run in the context of a Content script. The same code works fine on regular pages and in the extension's process (background page).
To work around the problem, use document.createElement('img') instead of new Image().
And don't forget to report the bug at https://code.google.com/p/chromium/issues/list.

raphael text() not working in ie9

Why is the following example not working in ie9?
http://jsfiddle.net/dzyyd/2/
It spits out a console error:
"Unexpected call to method or property access."
I found it pretty quickly. You created the element, but did not put it anywhere. Once it is added to the document body, everything seems to be fine.
this._width=300;
this._height=300;
this._bgSvgContainer = document.createElement("div");
//NOTE: add the created div to the body of the document so that it is displayed
document.body.appendChild(this._bgSvgContainer);
var bgCanvas = Raphael(this._bgSvgContainer, this._width, this._height);
this._bgCanvas = bgCanvas;
var num = this._bgCanvas.text(this._width-10,this._height-10,"1");
It's really hard to tell with such a tiny code-fragment (doesn't run on any browser for me), but it's probably a scope issue this in IE during events is completely different to this using the W3C event model. See: quirksmode-Event order-Problems of the Microsoft model

Resources