Get the title from a popup - javascript

This is a jQuery tooltip.
In a nutshell, the jQuery creates the popup from another HTML page.
EDIT
i put up an example. HERE
So I need to grab the title from the popup. When I use the document.title or whatever, it echos the title from the current page and not the popup.
<div id='JT_close_right'>"+title+"</div>
I need the title in a variable:
var title = (pop-up page's title)

simply use:
var title = $('#JT_close_right').html();
Since you are populating that element with the title in the function, you just need to grab that element by its id. The popup you are creating is not a separate window, but just using a div as an overlay overtop of the current content, so it does not have its own document.title for example, or document object for that matter.

Related

Is it possible to change BootstrapDialog title and other properties from the remote file?

I need to open a BootstrapDialog and load a remote page inside (PHP, CFM or whatever). I want to know if it's possible to change dialog properties (mainly the TITLE) from that loaded page. I tried to insert the following code but It doesn't work:
<script>
$('#openedDialog').setTitle('Blah, blah');
</script>
If I add:
alert($('#openedDialog'))
it works. So the object exists, it's just I don't have access to its methods.
Any ideas?
As you are using bootstrap modal the title element is using h4 tag with a class modal-title.So you can use text instead of setTitle
$('.modal-title').text("new title")
and if you are using this bootstrap dialog plugin then use
$('.bootstrap-dialog-title').text("new title")
or
var dialogInstance = new BootstrapDialog();
dialogInstance.setTitle('new title');
else if you given a id to the title then
$('#myTitleID').text("new title")

loading specific id content from html in dojo content pane

I am trying to load specific html id content in Dojo content pane on click of a tree node.
I have a long html, which has several headings. I am trying to load content from this html on click on a tree node. I am able to get html loaded, but I am not able to bring content with specific id on top of content pane.
Say my html is abc.html and it has several ids say id1, id2 ...
if I open this html in IE with argument abc.html, page gets loaded, with first line on top. Now if I open it with argument abc.html#id9
This specific section of html get loaded to top of IE window.
I am trying to achieve same effect in dojo content pane - here content is loaded in Dojo ContentPane on click on tree node and goal is load specific #id associated with that tree node in content pane, instead of loading top of html.
It never loads specific id content on top of content pane. It always load as if argument is abc.html. I do not see any effect of abc.html#id9
below is code snippet on how I am creating content pane and loading content on click on tree node.
....
var CenterPane = new ContentPane({//content pane at center for loading urls of selected designs
content:"Click to get the details about node",
region:"center"});
bordContainer.addChild(CenterPane);//add content pane to the border container
....
....
var fileTree = new Tree ({
model: treeModel,
showRoot: false,
openOnClick:true,
autoExpand:false,
_createTreeNode: function (args)
{
return new MyTreeNode(args);
},
onClick: function(args) {
CenterPane.set("href", vHtmlPath); }
....
vHtmlPath is dynamically set to abc.html#id9 or abc.html#id1 ....
ContentPane does not load into an iframe. If you want to move, you have to change the current page url.
For instance
CenterPane.set("href", vHtmlPath).then(function() {
document.location.href = "#id9"
}

Script to embed HTML content on page

The scenario: My company wants to have a "content builder" on our customer portal. Using this content builder, the user can check off their requested content (example: about the company, about our products, etc.)
Once the options are selected, I want to provide the user with a script they can place on their website. When run, the parameters in the script will reach out, call our CMS for the appropriate copy, and return the markup.. which should display within their browser.
My question is.. how do I go about doing this? I know how to get the HTML from the CMS, but how do I write the data back into the DOM? Should I just embed an IFRAME? Can I just write out div tags and such onto the host website? Any advice is appreciated, thanks in advance.
You can create markup to insert into the page.
You could add an id attribute to the script tag that gets embedded into the external site and have them place the script tag exactly where you want the content to appear.
<script id="myscripttag" src="..."></script>
then use some code like below to insert the markup before your script tag.
var insertMarkup = function(){
var scripttag = document.getElementById('myscripttag'),
YOURCONTENT = '<h1>hello</h1>',
//parentNode of script tag
p = scripttag.parentNode,
//new element to hold your content
n = document.createElement("div");
n.id = 'mynewdiv';
n.innerHTML = YOURCONTENT;
p.insertBefore(n,scripttag);
};
While a little bit more about the specific content would be helpful, the basic idea will be to use the innerhtml property of the DOM element into which you will be placing content. For example if you have a div with an id of "contentbox" you could write:
var x = htmlstringfromcms();
document.getElementById("contentbox").innerhtml=x;
if you want to append, rather than overwrite the content of the element try
var x = htmlstringformcms();
document.getElementById("contentbox").innerhtml+=x;

Javascript creating a link to another page with a JS function for that page

So I have a page that has multiple divs that can be toggled to be visible/invisible by the user.
Then I have another page that I want to link to something specific in the aforementioned page. How can I pass the javascript toggle code along with the link so that it displays the correct div, instead of just the default view.
You could use a url hash like site.com/page.html#div1
Then use javascript to parse the hash and decide wich div to show
var hash = window.location.hash;
var selectedDiv = hash.split('#')[1];
//Then show selectedDiv

Get javascript loaded content

Let's say I have a button on a page, if clicked it adds a div popup.
How can I access the div's content through JavaScript? Is this possible? I've tried searching the page with jQuery selectors but I did not find the div popup.
I have a bookmarklet that is similar to what follows:
javascript:(function() {
alert($('newDivId').val());
})();
...suppose that newDivId is the id of the newly created div, if I execute that code by clicking on the bookmarklet I get an error saying that val() cannot be invoked on a null object.
I do not have access to the page source; do you have any suggestion?
$('#id_of_div').html()
OR
$('.class_of_div').html()
OR
$('#id_of_div_parent div').html()
ETC.
If that doesn't work, you might be trying to select it before it has been full inserted into the DOM. Be sure it's fully loaded before you try to access it.

Categories