Change Content within a modal

Asked

Viewed 830 times

1

How can I load a modal and this modal have a button that when clicking exchange the content for another page of this modal that is already open, and when closing back to the previous content. I’m using the materialize front-end framework.

I’m having problems to elaborate the js in which change the content of the initial modal by another page, I can change the content by a text, but not open another page inside it.

  • The only way to display content from another modal page is with an iframe. And that is if the other site allows your content to be rendered in an iframe.

  • is missing information on your question. What modal are you using? jQuery Dialog? Or is it a Javascript modal? Enter your code to make it easier. When you say another page is talking about another url?

1 answer

1


Hello.

You need to load the data dynamically on the same page or from another. No iframe required. But it will be loaded the html of the page, or even of a div or other specific tag using a very simple jQuery (requires basic knowledge). But this is also possible using angular (requires intermediate knowledge).

In jQuery I use this code for that:

$('#MytargetDiv').load('https://www.example.org/anyPage.html #MytargetContent', function() {
// escreva suas funções ou ações aqui
// você pode alterar, ocultar ou exibir o conteúdo recebido como no exemplo abaixo
$('p.summary').hide(); // ou
$('div img.thumb').remove(); // se o carregamento for bem sucedido estas funções ou ações serão executadas. isso permite infinitas possibilidades.
});

If you need or want to use the full content you can use it this way.

$('.Class4TargetDiv').load('https://www.example.org #TargetDivWithContent');

or

$('#MyTargetDiv').load('https://www.example.org .TargetDivWithContent');

Remember that to identify the element you want to load you can identify it by Id (#elementid) or by a CSS class (.anyclass).

Note: You must apply or call this code in the event of the link or the button you will use to trigger the content change.

I hope it will be useful.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.