How can I accsess the data attribute in plugin code? - firebreath

this is the tag the plugin uses <object type="something" data="myfile.mytype"></object>.
now I want to use the src value in my plugin source code, how can I access that?

try {
std::string test = m_host->getDOMElement()->getProperty<std::string>("src");
} catch (...) {
// There wasn't a value to fetch
}

Related

How do I create the onClick function for a button with Kotlinx.html?

I am using Kotlin's html library kotlinx.html for dynamic html building.
I want to create a button which triggers a function when clicked. This is my current code:
class TempStackOverflow(): Template<FlowContent> {
var counter: Int = 1
override fun FlowContent.apply() {
div {
button(type = ButtonType.button) {
onClick = "${clicked()}"
}
}
}
fun clicked() {
counter++
}
}
This results in the following source code:
<button type="button" onclick="kotlin.Unit">testkotlin.Unit</button>
Which gives this error when clicked (from Chrome developer console):
Uncaught ReferenceError: kotlin is not defined at HTMLButtonElement.onclick
I have tried several approves, and search for a solution - but could not find the proper documentation.
I am not a Kotlin expert, but it's perfectly possible to write event handlers using kotlinx. Rather than:
onClick = "${clicked()}"
have you tried using this?
onClickFunction = { clicked() }
If you really need a bit on Javascript here, you can type this:
unsafe {
+"<button onClick = console.log('!')>Test</button>"
}
Good for debugging and tests, but not very nice for production code.
Unfortunately, you're completely missing the point of the kotlinx.html library. It can only render HTML for you, it's not supposed to be dynamic kotlin->js bridge, like Vaadin or GWT. So, you just set result of clicked function converted to String to onClick button's property, which is effective kotlin.Unit, because kotlin.Unit is default return value of a function if you not specify another type directly.
fun clicked() {
counter++
}
is the same as
fun clicked():Unit {
counter++
}
and same as
fun clicked():Kotlin.Unit {
counter++
}
So, when you set "${clicked()}" to some property it actually exec function (your counter is incremented here) and return Koltin.Unit value, which is becomes "Kotlin.Unit" string when it rendered inside "${}" template

Adding html elements to page with MVC Razor pages

On the html for my page I have a <script id="pagedata"></script> element which I would like to add an element to only if a certain partial is rendered. In my layout.cshtml I have the following:
#if (Brand != null)
{
#Html.Partial("_UseApp");
}
And in my _UseApp.cshtml:
#{
var iosAppUrl = // retrieve iosLink from our CRM database
var androidUrl = // retrieve android link from our CRM database
// Here I want to add the above variables to the <script id=pagedata> in the html page. Something
like this:
PageData.AddPageData("appstore", iosAppUrl);
PageData.AddPageData("playstore", androidUrl);
I cannot work out how to do this - I set breakpoints in the UseApp.cshtml file and the file is being called, but I don't know how to add these script elements. I don't want to just add them into the layout file because I want to keep the app logic separate. Can anyone help? Thanks
My approach to this would be to use jQuery, as reading HTML elements in C# is rather difficult.
In the script below, it checks if the HTML exists, and if it does, we will assign an attribute to it. The second argument in attr() will be your link, note that you can use C# to get the value from your Db, by using the model or ViewBag.
#section Scripts{
<script>
$(document).ready(function () { // on ready
if ($("#replaceWithYourId").length) { // check if ID exists
$("#pagedata").attr("data-playstore", "link") // use jQuery attr method.
}
});
</script>
}

sending , retrieving data from designer of pages using query string of URL

I have a iframe in aspx page whose src property is set to html page url along with data is sent syntax is as follows :
<iframe src="testing.htm?info1='Hello'"></iframe>
and on html page in onload of Body tag i have called a function that will read from the query string and assign data to a text box. Code is as follows:
var info;
function _Form_Loader() {
try {
debugger;
Info = request.QueryString('info1'); // input is the textbox.
var Txt = $("#Input1");
Txt.Text = Info ;
} catch (e) {
}
}
What is wrong here i suppose query string is the problem .
thanks in advance.
You are assiging src to that textbox but where u are assigining for that
I think u need to pass Txt.Text = Info; or just try $("#Input1").val(Info);
Try this ...

NPAPI Plugin[FireFox]: Invoke() / HasProperty() / HasMethod() not getting called

I am developing NPAPI Plugin for Firefox on windows. here is the my java script:
document.addEventListener('load', documentLoad, true);
function loadPlugin(doc)
{
var objWebMon = doc.getElementById("my_firefox");
if(!objWebMon)
{
var objWebMonEmbed = doc.createElement('embed');
objWebMonEmbed.setAttribute('id', 'my_firefox');
objWebMonEmbed.setAttribute('type', 'application/npplugin');
objWebMonEmbed.setAttribute('style', 'height: 10px; width:10px; display:block;');
if(doc.body)
{
doc.body.insertBefore(objWebMonEmbed, doc.body.firstChild);
}
}
}
function documentLoad(event) {
try
{
var doc = event.originalTarget; // doc is document that triggered "onload" event
loadPlugin(doc);
var myplugin = doc.getElementById('my_firefox');
if(myplugin)
{
myplugin();
myplugin.myAction();
}
} catch(err)
{
}
}
as I am calling myplugin()
bool ScriptablePluginObject::InvokeDefault(const NPVariant *args, uint32_t argCount, NPVariant *result)
gets called sucessfully but on calling function myplugin.myAction()
bool ScriptablePluginObject::Invoke(NPIdentifier name, const NPVariant *args,
uint32_t argCount, NPVariant *result)
function doesn't called. I have declared myAction inside ScriptablePluginObject::HasProperty(NPIdentifier name) even HasProperty method is not getting called.
Inside catch block i am getting this error. TypeError: fasso.myAction is not a function.
Here are a couple of things to try:
Use an object tag instead of an embed -- I've had more consistent success with object tags, despite the wide popularity of using embed
Never ever ever set the type of an object or embed tag before you add it to the DOM -- doing so causes it to instantiate the plugin and then puts it in a kinda weird state when it gets moved. I don't think this is causing your issue this time, but it's worth trying.
You may need a slight delay between inserting hte plugin into the DOM and using it. Try adding a setTimeout with a delay of 50ms and accessing the plugin in the callback function.
Honestly, #3 is the one I think most likely will make a difference, but I present the other two as they have bitten me on weird things in the past. Good luck!

How to localStorage properly with one name?

I want to use localStorage["something"] = item; but the script is loaded in every page, which creates files like:
http_www.google.bg_0.localstorage
http_stackoverflow.com_0.localstorage`
I want the current webpage data to be stored in one file, just like the normal extensions do. But I found that this is possible only while localStorage is accessed from popups.html. Then the outputted file is like:
chrome-extension_cognfheolmcnfppokallnahdaibbaabe_0.localstorage
Does somebody knows how to do that? Or maybe how to use the localStorage from popup.html, without showing it?
EDIT:
When I try to use a function from the background.html like:
chrome.extension.getBackgroundPage().setItem("currentWord",s);
Nothing gets called, whu could this happen?
Here's my background.html:
<html><head><script>
var logging = false;
function setItem(key, value) {
alert("Saving setting");
try {
log("Inside setItem:" + key + ":" + value);
window.localStorage.removeItem(key);
window.localStorage.setItem(key, value);
} catch(e) {
alert("Error inside setItem: " + e);
}
}
function clear() {
window.localStorage.clear();
}
function log(txt) {
if(logging) console.log(txt);
}
</script></head></html>
You need to put values to a local storage inside a background page. In order to do that you need to pass your value there from a content script using message passing.