I am trying to open a popup windows but the button's onclick content is stored in a variable. Thsi is my approach:
var page = 'window.open(\'ticket.html?wallet='+global_wallet+'\',\'popUpWindow\');';
document.getElementById('EditButton').onclick=page;
This is not working. Not popup being displayed. Something is missing and i don't figure out what is it...
Regards,
The onclick property is supposed to be a JavaScript function, not a string like you are trying.
You can pass a function:
document.getElementById('EditButton').onclick = function(){
window.open('ticket.html?wallet='+global_wallet,'popUpWindow');
};
Or if for some reason you have to use the string, you can set the onclick attribute. In this case you need to use setAttibute() instead of the onclick property.
document.getElementById('EditButton').setAttribute('onclick', page);
Related
I want to Change the value assigned to a Document Property in spot fire. Lets say i have created a new document property called "Test1" as a string and assign it a value "a". Is there are way to change this value using Javascript every time i load the spotfire dashboard ?
I'm unaware of a way to use JavaScript for this, but you can assign a string document property via custom expression (if it's a List Box) or run an IronPython script each time the value changes. So, you could set the expression to the current date, datetimenow() and then every time it's loaded the IronPython script would fire. However, I don't see why you'd need the property control for this.
I suppose it really depends on what you want the document property to be set to. Is it data from your tables? Output from complex code? These are all things to consider.
1) Create an input type property control using the Document Property you want to change.
2) Edit Html to assign parent element an id say "testInput". And add the script as shown below in the Edit HTML window.
<span id="testInput"><SpotfireControl id="7db34e6c423240f59fc99e6b80fa23ec" /></span>
<script>
$("#testInput input").val("after");
$("#testInput input").focus();
$("#testInput input").blur();
</script>
3) This script will change the document property value to "after" whenever you open a file.
As you comment seemed to suggest, something you can do is write this code in Python and attach the script to an action control, e.i. a Link or a Button. Something simple like: Document.Properties["Test1"] = newValue
or even: Document.Properties[changingProperty] = newValue
allowing the code to be more reusable.
Then you insert Javascript into the Text Area as well to the effect of: $("#VeryLongSpotfireControlID").click();
Which should simulate clicking on action control, which in turn triggers the Python script to update the value. Just be careful not to use this approach when it would result in reloading the text area HTML, as this will re-trigger the Javascript, thus creating an endless loop.
I believe I have found a possible solution/work-around for the issue, entirely based on pure JavaScript (since TIBCO removed jQuery starting from Spotfire X). The solution is to force a simulated Enter Keystroke while focusing the input box to trigger updating the Document Property. (No data function and R needed)
HTML (SpotfireControl Element is an single line input-box for a Doc. Prop.):
<div id="container"><SpotfireControl id="b8534f13dc62416db6d4eaab16030f5e" /></div>
JS (focus and blur might no longer be needed for this solution, but I'm still keeping them just in case):
const inputConfirmationEvent = new KeyboardEvent("keypress", {
keyCode: 13,
bubbles: true,
cancelable: false
});
var elem = document.querySelector("#container input");
elem.value = "stringValue";
elem.blur();
elem.focus();
document.querySelector("#container input").dispatchEvent(inputConfirmationEvent);
Hope it helps someone.
Best,
Aaron
I want to pull the onclick information from an a tag. I know how to do this normally and I've confirmed it works via the console. However, it returns null when attempted through an extension. Is this possible via an extension and if so: what strange method must be employed?
Example:
On the page: text
I'd like to be able to grab that something(stuff,otherstuff).
However, pure JS didn't work: String(document.getElementsByTagName("a")[10].onclick)
And neither did jQuery: String($(".tableclass").find("tbody").find("a")[10].onclick)
Both of the above working when entered into the console.
First of all, you can never read the onclick property that was set by a page because extension code runs in an isolated scope.
Secondly, even if the code was not isolated, the onclick property of <a onclick="foo"></a> may not have the value foo you are expecting. That is because a property is not the same thing as an HTML attribute.
Therefore, if you want to access the string value of an onclick attribute you can and should use linkElement.getAttribute('onclick'); instead.
Is this what you mean, that you want to change a href of the link? You can do it like this:
html:
<a href='foo' class='link-to-swap'>link</a>
javascript:
$(document).ready(function(){
$('.link-to-swap').click(function(e){
e.preventDefault();
var grabbedData = $(this).attr('data-id')
$(this).attr('href',grabbedData)
return false
})
})
here is the fiddle:
https://jsfiddle.net/cp6x9pf5/1/
I call my Dialog with a link
<li>" + text + "</li>;
Is there away I can pass a variable which is also the id, to the refPerson beforeshow function? I am trying to not have to make a phony hidden element. I have tried a bunch of different ways but nothing seems to pass the var.
$(document).on('pagebeforeshow','#refPerson', function(){
});
I have changed how the dialog is called to making the onclick of the link a function that dynamically opens the dialog but I couldnt get that to correctly pass the param either. I just need to get the clicked links ID to the beforeshow function, or somehow pass a variable to it
You can consider using html5 data-* attribute.
refer to this
Using .attr() to retrieve the value from the attribute. Refer to api
As mentioned before, you can use .attr(), here's an example:
<li><a href='#' onclick='getId(this);' data-transition='pop' id='someId'>Some Text</a></li>
<script>
function getId(e){
var myId = $(e).attr("id");
console.log(myId);
//yourcode...and then redirect...
$.mobile.navigate( "#refPerson" );
}
</script>
You can also assign a global javascript variable and retrieve it on your dialog, like this:
function getId(e){
window.myId= $(e).attr("id");
console.log(window.myId);
//yourcode...and then redirect...
$.mobile.navigate( "#refPerson" );
}
I personally use the sweet-alert plugin to handle dialogs and messages.
I just changed the onclick of the link to a function and passed the param. Then dynamically opened the new dialog. It just seems like the easiest solution to my problem
I have a javascript function:
function foo() { return "/a/b/SomeApi"; }
then I have a href link in my web page. I want this link to point to the value returned by my javascript function, so that when the user clicks the link, it's as if the user had clicked a link with url /a/b/SomeApi.
I tried following:
Click
But the result of this is the browser would open a new window showing the literal value /a/b/SomeApi instead of sending a request to the server.
Any suggestions? Thanks.
Instead of returning the string, set the location of the current page with it, like this...
function foo() { document.location.href = "/a/b/SomeApi"; }
As pointed out by #haim770 - these are not the droids you are looking for.
If you want to specifically set the href attribute, you must do it from outside of the link. Firstly you should give your link an id attribute, such as this...
<a id="myAnchor">Click</a>
This piece of code should then be placed either after the element in the page, or as part of a "document loaded" piece of code.
document.getElementById("myAnchor").href = "/a/b/SomeApi";
If you were using jQuery (which is not in your list of tags) you could do something like this...
$(function(){
$("#myAnchor").attr("href", "/a/b/SomeApi")
});
I don't think HREF was ever meant to be dynamic; for that, just use the onclick property, such as :
Click
My problem is that I have several a tag and a javascript. When click the a tag, JavaScript works and get the tag value. It's okey but I want to assign this javascript variable to session or asp.net's variable. Because a href will goes another page and I need a href value. Also a href inside a SQL loop.
How will I do ? Is there another way without JavaScript ?
You should use QueryString. No need for any javascript.
Click
In you .net code:
var Id = int.Parse(Request.QueryString["id"]);